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-2004, Jouni Malinen <jkmaline@cc.hut.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
19 #include <linux/config.h>
20 #include <linux/version.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/proc_fs.h>
25 #include <linux/if_arp.h>
26 #include <linux/delay.h>
27 #include <linux/random.h>
28 #include <linux/workqueue.h>
29 #include <linux/kmod.h>
30 #include <linux/rtnetlink.h>
31 #include <linux/wireless.h>
32 #include <net/iw_handler.h>
33 #include <asm/uaccess.h>
35 #include "hostap_wlan.h"
36 #include "hostap_80211.h"
37 #include "hostap_ap.h"
39 #include "hostap_crypt.h"
41 MODULE_AUTHOR("Jouni Malinen");
42 MODULE_DESCRIPTION("Host AP common routines");
43 MODULE_LICENSE("GPL");
45 /* Old hostap_crypt module is now part of hostap module. */
46 #include "hostap_crypt.c"
48 #define TX_TIMEOUT (2 * HZ)
50 #define PRISM2_MAX_FRAME_SIZE 2304
51 #define PRISM2_MIN_MTU 256
53 #define PRISM2_MAX_MTU (PRISM2_MAX_FRAME_SIZE - (6 /* LLC */ + 8 /* WEP */))
57 static int prism2_wds_add(local_info_t
*local
, u8
*remote_addr
,
59 static int prism2_wds_del(local_info_t
*local
, u8
*remote_addr
,
60 int rtnl_locked
, int do_not_remove
);
63 static int prism2_ap_get_sta_qual(local_info_t
*local
, struct sockaddr addr
[],
64 struct iw_quality qual
[], int buf_size
,
66 static int prism2_ap_translate_scan(struct net_device
*dev
, char *buffer
);
67 static int prism2_hostapd(struct ap_data
*ap
,
68 struct prism2_hostapd_param
*param
);
69 static void * ap_crypt_get_ptrs(struct ap_data
*ap
, u8
*addr
, int permanent
,
70 struct prism2_crypt_data
***crypt
);
71 static void ap_control_kickall(struct ap_data
*ap
);
72 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
73 static int ap_control_add_mac(struct mac_restrictions
*mac_restrictions
,
75 static int ap_control_del_mac(struct mac_restrictions
*mac_restrictions
,
77 static void ap_control_flush_macs(struct mac_restrictions
*mac_restrictions
);
78 static int ap_control_kick_mac(struct ap_data
*ap
, struct net_device
*dev
,
80 #endif /* !PRISM2_NO_KERNEL_IEEE80211_MGMT */
83 static const long freq_list
[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
84 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
85 #define FREQ_COUNT (sizeof(freq_list) / sizeof(freq_list[0]))
88 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
89 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */
90 static unsigned char rfc1042_header
[] =
91 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
92 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
93 static unsigned char bridge_tunnel_header
[] =
94 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
95 /* No encapsulation header if EtherType < 0x600 (=length) */
98 /* FIX: these could be compiled separately and linked together to hostap.o */
99 #include "hostap_ap.c"
100 #include "hostap_info.c"
101 #include "hostap_ioctl.c"
102 #include "hostap_proc.c"
103 #include "hostap_80211_rx.c"
104 #include "hostap_80211_tx.c"
107 struct net_device
* hostap_add_interface(struct local_info
*local
,
108 int type
, int rtnl_locked
,
112 struct net_device
*dev
, *mdev
;
113 struct hostap_interface
*iface
;
116 dev
= alloc_etherdev(sizeof(struct hostap_interface
));
120 iface
= netdev_priv(dev
);
122 iface
->local
= local
;
124 list_add(&iface
->list
, &local
->hostap_interfaces
);
127 memcpy(dev
->dev_addr
, mdev
->dev_addr
, ETH_ALEN
);
128 dev
->base_addr
= mdev
->base_addr
;
129 dev
->irq
= mdev
->irq
;
130 dev
->mem_start
= mdev
->mem_start
;
131 dev
->mem_end
= mdev
->mem_end
;
133 hostap_setup_dev(dev
, local
, 0);
134 dev
->destructor
= free_netdev
;
136 sprintf(dev
->name
, "%s%s", prefix
, name
);
141 if (strchr(dev
->name
, '%'))
142 ret
= dev_alloc_name(dev
, dev
->name
);
145 ret
= register_netdevice(dev
);
151 printk(KERN_WARNING
"%s: failed to add new netdevice!\n",
157 printk(KERN_DEBUG
"%s: registered netdevice %s\n",
158 mdev
->name
, dev
->name
);
164 void hostap_remove_interface(struct net_device
*dev
, int rtnl_locked
,
165 int remove_from_list
)
167 struct hostap_interface
*iface
;
172 iface
= netdev_priv(dev
);
174 if (remove_from_list
) {
175 list_del(&iface
->list
);
178 if (dev
== iface
->local
->ddev
)
179 iface
->local
->ddev
= NULL
;
180 else if (dev
== iface
->local
->apdev
)
181 iface
->local
->apdev
= NULL
;
182 else if (dev
== iface
->local
->stadev
)
183 iface
->local
->stadev
= NULL
;
186 unregister_netdevice(dev
);
188 unregister_netdev(dev
);
190 /* dev->destructor = free_netdev() will free the device data, including
191 * private data, when removing the device */
195 static inline int prism2_wds_special_addr(u8
*addr
)
197 if (addr
[0] || addr
[1] || addr
[2] || addr
[3] || addr
[4] || addr
[5])
204 static int prism2_wds_add(local_info_t
*local
, u8
*remote_addr
,
207 struct net_device
*dev
;
208 struct list_head
*ptr
;
209 struct hostap_interface
*iface
, *empty
, *match
;
211 empty
= match
= NULL
;
212 read_lock_bh(&local
->iface_lock
);
213 list_for_each(ptr
, &local
->hostap_interfaces
) {
214 iface
= list_entry(ptr
, struct hostap_interface
, list
);
215 if (iface
->type
!= HOSTAP_INTERFACE_WDS
)
218 if (prism2_wds_special_addr(iface
->u
.wds
.remote_addr
))
220 else if (memcmp(iface
->u
.wds
.remote_addr
, remote_addr
,
226 if (!match
&& empty
&& !prism2_wds_special_addr(remote_addr
)) {
227 /* take pre-allocated entry into use */
228 memcpy(empty
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
229 read_unlock_bh(&local
->iface_lock
);
230 printk(KERN_DEBUG
"%s: using pre-allocated WDS netdevice %s\n",
231 local
->dev
->name
, empty
->dev
->name
);
234 read_unlock_bh(&local
->iface_lock
);
236 if (!prism2_wds_special_addr(remote_addr
)) {
239 hostap_add_sta(local
->ap
, remote_addr
);
242 if (local
->wds_connections
>= local
->wds_max_connections
)
245 /* verify that there is room for wds# postfix in the interface name */
246 if (strlen(local
->dev
->name
) > IFNAMSIZ
- 5) {
247 printk(KERN_DEBUG
"'%s' too long base device name\n",
252 dev
= hostap_add_interface(local
, HOSTAP_INTERFACE_WDS
, rtnl_locked
,
253 local
->ddev
->name
, "wds%d");
257 iface
= netdev_priv(dev
);
258 memcpy(iface
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
260 local
->wds_connections
++;
266 static int prism2_wds_del(local_info_t
*local
, u8
*remote_addr
,
267 int rtnl_locked
, int do_not_remove
)
270 struct list_head
*ptr
;
271 struct hostap_interface
*iface
, *selected
= NULL
;
273 write_lock_irqsave(&local
->iface_lock
, flags
);
274 list_for_each(ptr
, &local
->hostap_interfaces
) {
275 iface
= list_entry(ptr
, struct hostap_interface
, list
);
276 if (iface
->type
!= HOSTAP_INTERFACE_WDS
)
279 if (memcmp(iface
->u
.wds
.remote_addr
, remote_addr
,
285 if (selected
&& !do_not_remove
)
286 list_del(&selected
->list
);
287 write_unlock_irqrestore(&local
->iface_lock
, flags
);
291 memset(selected
->u
.wds
.remote_addr
, 0, ETH_ALEN
);
293 hostap_remove_interface(selected
->dev
, rtnl_locked
, 0);
294 local
->wds_connections
--;
298 return selected
? 0 : -ENODEV
;
302 u16
hostap_tx_callback_register(local_info_t
*local
,
303 void (*func
)(struct sk_buff
*, int ok
, void *),
307 struct hostap_tx_callback_info
*entry
;
309 entry
= (struct hostap_tx_callback_info
*) kmalloc(sizeof(*entry
),
317 spin_lock_irqsave(&local
->lock
, flags
);
318 entry
->idx
= local
->tx_callback
? local
->tx_callback
->idx
+ 1 : 1;
319 entry
->next
= local
->tx_callback
;
320 local
->tx_callback
= entry
;
321 spin_unlock_irqrestore(&local
->lock
, flags
);
327 int hostap_tx_callback_unregister(local_info_t
*local
, u16 idx
)
330 struct hostap_tx_callback_info
*cb
, *prev
= NULL
;
332 spin_lock_irqsave(&local
->lock
, flags
);
333 cb
= local
->tx_callback
;
334 while (cb
!= NULL
&& cb
->idx
!= idx
) {
340 local
->tx_callback
= cb
->next
;
342 prev
->next
= cb
->next
;
345 spin_unlock_irqrestore(&local
->lock
, flags
);
351 /* val is in host byte order */
352 int hostap_set_word(struct net_device
*dev
, int rid
, u16 val
)
354 struct hostap_interface
*iface
;
355 u16 tmp
= cpu_to_le16(val
);
356 iface
= netdev_priv(dev
);
357 return iface
->local
->func
->set_rid(dev
, rid
, &tmp
, 2);
361 int hostap_set_string(struct net_device
*dev
, int rid
, const char *val
)
363 struct hostap_interface
*iface
;
364 char buf
[MAX_SSID_LEN
+ 2];
367 iface
= netdev_priv(dev
);
369 if (len
> MAX_SSID_LEN
)
371 memset(buf
, 0, sizeof(buf
));
372 buf
[0] = len
; /* little endian 16 bit word */
373 memcpy(buf
+ 2, val
, len
);
375 return iface
->local
->func
->set_rid(dev
, rid
, &buf
, MAX_SSID_LEN
+ 2);
379 u16
hostap_get_porttype(local_info_t
*local
)
381 if (local
->iw_mode
== IW_MODE_ADHOC
&& local
->pseudo_adhoc
)
382 return HFA384X_PORTTYPE_PSEUDO_IBSS
;
383 if (local
->iw_mode
== IW_MODE_ADHOC
)
384 return HFA384X_PORTTYPE_IBSS
;
385 if (local
->iw_mode
== IW_MODE_INFRA
)
386 return HFA384X_PORTTYPE_BSS
;
387 if (local
->iw_mode
== IW_MODE_REPEAT
)
388 return HFA384X_PORTTYPE_WDS
;
389 if (local
->iw_mode
== IW_MODE_MONITOR
)
390 return HFA384X_PORTTYPE_PSEUDO_IBSS
;
391 return HFA384X_PORTTYPE_HOSTAP
;
395 int hostap_set_encryption(local_info_t
*local
)
398 int i
, keylen
, len
, idx
;
399 char keybuf
[WEP_KEY_LEN
+ 1];
400 enum { NONE
, WEP
, OTHER
} encrypt_type
;
402 idx
= local
->tx_keyidx
;
403 if (local
->crypt
[idx
] == NULL
|| local
->crypt
[idx
]->ops
== NULL
)
405 else if (strcmp(local
->crypt
[idx
]->ops
->name
, "WEP") == 0)
408 encrypt_type
= OTHER
;
410 if (local
->func
->get_rid(local
->dev
, HFA384X_RID_CNFWEPFLAGS
, &val
, 2,
412 printk(KERN_DEBUG
"Could not read current WEP flags.\n");
418 if (encrypt_type
!= NONE
|| local
->privacy_invoked
)
419 val
|= HFA384X_WEPFLAGS_PRIVACYINVOKED
;
421 val
&= ~HFA384X_WEPFLAGS_PRIVACYINVOKED
;
423 if (local
->open_wep
|| encrypt_type
== NONE
||
424 ((local
->ieee_802_1x
|| local
->wpa
) && local
->host_decrypt
))
425 val
&= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED
;
427 val
|= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED
;
429 if ((encrypt_type
!= NONE
|| local
->privacy_invoked
) &&
430 (encrypt_type
== OTHER
|| local
->host_encrypt
))
431 val
|= HFA384X_WEPFLAGS_HOSTENCRYPT
;
433 val
&= ~HFA384X_WEPFLAGS_HOSTENCRYPT
;
434 if ((encrypt_type
!= NONE
|| local
->privacy_invoked
) &&
435 (encrypt_type
== OTHER
|| local
->host_decrypt
))
436 val
|= HFA384X_WEPFLAGS_HOSTDECRYPT
;
438 val
&= ~HFA384X_WEPFLAGS_HOSTDECRYPT
;
440 if (val
!= old_val
&&
441 hostap_set_word(local
->dev
, HFA384X_RID_CNFWEPFLAGS
, val
)) {
442 printk(KERN_DEBUG
"Could not write new WEP flags (0x%x)\n",
447 if (encrypt_type
!= WEP
)
450 /* 104-bit support seems to require that all the keys are set to the
452 keylen
= 6; /* first 5 octets */
453 len
= local
->crypt
[idx
]->ops
->get_key(keybuf
, sizeof(keybuf
),
454 NULL
, local
->crypt
[idx
]->priv
);
455 if (idx
>= 0 && idx
< WEP_KEYS
&& len
> 5)
456 keylen
= WEP_KEY_LEN
+ 1; /* first 13 octets */
458 for (i
= 0; i
< WEP_KEYS
; i
++) {
459 memset(keybuf
, 0, sizeof(keybuf
));
460 if (local
->crypt
[i
]) {
461 (void) local
->crypt
[i
]->ops
->get_key(
462 keybuf
, sizeof(keybuf
),
463 NULL
, local
->crypt
[i
]->priv
);
465 if (local
->func
->set_rid(local
->dev
,
466 HFA384X_RID_CNFDEFAULTKEY0
+ i
,
468 printk(KERN_DEBUG
"Could not set key %d (len=%d)\n",
473 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFWEPDEFAULTKEYID
, idx
)) {
474 printk(KERN_DEBUG
"Could not set default keyid %d\n", idx
);
481 printk(KERN_DEBUG
"%s: encryption setup failed\n", local
->dev
->name
);
486 int hostap_set_antsel(local_info_t
*local
)
491 if (local
->antsel_tx
!= HOSTAP_ANTSEL_DO_NOT_TOUCH
&&
492 local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_READMIF
,
493 HFA386X_CR_TX_CONFIGURE
,
495 val
&= ~(BIT(2) | BIT(1));
496 switch (local
->antsel_tx
) {
497 case HOSTAP_ANTSEL_DIVERSITY
:
500 case HOSTAP_ANTSEL_LOW
:
502 case HOSTAP_ANTSEL_HIGH
:
507 if (local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_WRITEMIF
,
508 HFA386X_CR_TX_CONFIGURE
, &val
, NULL
)) {
509 printk(KERN_INFO
"%s: setting TX AntSel failed\n",
515 if (local
->antsel_rx
!= HOSTAP_ANTSEL_DO_NOT_TOUCH
&&
516 local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_READMIF
,
517 HFA386X_CR_RX_CONFIGURE
,
519 val
&= ~(BIT(1) | BIT(0));
520 switch (local
->antsel_rx
) {
521 case HOSTAP_ANTSEL_DIVERSITY
:
523 case HOSTAP_ANTSEL_LOW
:
526 case HOSTAP_ANTSEL_HIGH
:
527 val
|= BIT(0) | BIT(1);
531 if (local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_WRITEMIF
,
532 HFA386X_CR_RX_CONFIGURE
, &val
, NULL
)) {
533 printk(KERN_INFO
"%s: setting RX AntSel failed\n",
543 int hostap_set_roaming(local_info_t
*local
)
547 switch (local
->host_roaming
) {
549 val
= HFA384X_ROAMING_HOST
;
552 val
= HFA384X_ROAMING_DISABLED
;
556 val
= HFA384X_ROAMING_FIRMWARE
;
560 return hostap_set_word(local
->dev
, HFA384X_RID_CNFROAMINGMODE
, val
);
564 int hostap_set_auth_algs(local_info_t
*local
)
566 int val
= local
->auth_algs
;
567 /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication
568 * set to include both Open and Shared Key flags. It tries to use
569 * Shared Key authentication in that case even if WEP keys are not
570 * configured.. STA f/w v0.7.6 is able to handle such configuration,
571 * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */
572 if (local
->sta_fw_ver
< PRISM2_FW_VER(0,7,0) &&
573 val
!= PRISM2_AUTH_OPEN
&& val
!= PRISM2_AUTH_SHARED_KEY
)
574 val
= PRISM2_AUTH_OPEN
;
576 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFAUTHENTICATION
, val
)) {
577 printk(KERN_INFO
"%s: cnfAuthentication setting to 0x%x "
578 "failed\n", local
->dev
->name
, local
->auth_algs
);
586 void hostap_dump_rx_header(const char *name
, const struct hfa384x_rx_frame
*rx
)
590 status
= __le16_to_cpu(rx
->status
);
592 printk(KERN_DEBUG
"%s: RX status=0x%04x (port=%d, type=%d, "
593 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
595 name
, status
, (status
>> 8) & 0x07, status
>> 13, status
& 1,
596 rx
->silence
, rx
->signal
, rx
->rate
, rx
->rxflow
, jiffies
);
598 fc
= __le16_to_cpu(rx
->frame_control
);
599 printk(KERN_DEBUG
" FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
601 fc
, WLAN_FC_GET_TYPE(fc
), WLAN_FC_GET_STYPE(fc
),
602 __le16_to_cpu(rx
->duration_id
), __le16_to_cpu(rx
->seq_ctrl
),
603 __le16_to_cpu(rx
->data_len
),
604 fc
& WLAN_FC_TODS
? " [ToDS]" : "",
605 fc
& WLAN_FC_FROMDS
? " [FromDS]" : "");
607 printk(KERN_DEBUG
" A1=" MACSTR
" A2=" MACSTR
" A3=" MACSTR
" A4="
609 MAC2STR(rx
->addr1
), MAC2STR(rx
->addr2
), MAC2STR(rx
->addr3
),
612 printk(KERN_DEBUG
" dst=" MACSTR
" src=" MACSTR
" len=%d\n",
613 MAC2STR(rx
->dst_addr
), MAC2STR(rx
->src_addr
),
614 __be16_to_cpu(rx
->len
));
618 void hostap_dump_tx_header(const char *name
, const struct hfa384x_tx_frame
*tx
)
622 printk(KERN_DEBUG
"%s: TX status=0x%04x retry_count=%d tx_rate=%d "
623 "tx_control=0x%04x; jiffies=%ld\n",
624 name
, __le16_to_cpu(tx
->status
), tx
->retry_count
, tx
->tx_rate
,
625 __le16_to_cpu(tx
->tx_control
), jiffies
);
627 fc
= __le16_to_cpu(tx
->frame_control
);
628 printk(KERN_DEBUG
" FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
630 fc
, WLAN_FC_GET_TYPE(fc
), WLAN_FC_GET_STYPE(fc
),
631 __le16_to_cpu(tx
->duration_id
), __le16_to_cpu(tx
->seq_ctrl
),
632 __le16_to_cpu(tx
->data_len
),
633 fc
& WLAN_FC_TODS
? " [ToDS]" : "",
634 fc
& WLAN_FC_FROMDS
? " [FromDS]" : "");
636 printk(KERN_DEBUG
" A1=" MACSTR
" A2=" MACSTR
" A3=" MACSTR
" A4="
638 MAC2STR(tx
->addr1
), MAC2STR(tx
->addr2
), MAC2STR(tx
->addr3
),
641 printk(KERN_DEBUG
" dst=" MACSTR
" src=" MACSTR
" len=%d\n",
642 MAC2STR(tx
->dst_addr
), MAC2STR(tx
->src_addr
),
643 __be16_to_cpu(tx
->len
));
647 int hostap_80211_header_parse(struct sk_buff
*skb
, unsigned char *haddr
)
649 memcpy(haddr
, skb
->mac
.raw
+ 10, ETH_ALEN
); /* addr2 */
654 int hostap_80211_prism_header_parse(struct sk_buff
*skb
, unsigned char *haddr
)
656 if (*(u32
*)skb
->mac
.raw
== LWNG_CAP_DID_BASE
) {
657 memcpy(haddr
, skb
->mac
.raw
+
658 sizeof(struct linux_wlan_ng_prism_hdr
) + 10,
659 ETH_ALEN
); /* addr2 */
660 } else { /* (*(u32 *)skb->mac.raw == htonl(LWNG_CAPHDR_VERSION)) */
661 memcpy(haddr
, skb
->mac
.raw
+
662 sizeof(struct linux_wlan_ng_cap_hdr
) + 10,
663 ETH_ALEN
); /* addr2 */
669 int hostap_80211_get_hdrlen(u16 fc
)
673 switch (WLAN_FC_GET_TYPE(fc
)) {
674 case WLAN_FC_TYPE_DATA
:
675 if ((fc
& WLAN_FC_FROMDS
) && (fc
& WLAN_FC_TODS
))
676 hdrlen
= 30; /* Addr4 */
678 case WLAN_FC_TYPE_CTRL
:
679 switch (WLAN_FC_GET_STYPE(fc
)) {
680 case WLAN_FC_STYPE_CTS
:
681 case WLAN_FC_STYPE_ACK
:
695 struct net_device_stats
*hostap_get_stats(struct net_device
*dev
)
697 struct hostap_interface
*iface
;
698 iface
= netdev_priv(dev
);
699 return &iface
->stats
;
703 static int prism2_close(struct net_device
*dev
)
705 struct hostap_interface
*iface
;
708 PDEBUG(DEBUG_FLOW
, "%s: prism2_close\n", dev
->name
);
710 iface
= netdev_priv(dev
);
711 local
= iface
->local
;
713 if (dev
== local
->ddev
) {
714 prism2_sta_deauth(local
, WLAN_REASON_DEAUTH_LEAVING
);
716 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
717 if (!local
->hostapd
&& dev
== local
->dev
&&
718 (!local
->func
->card_present
|| local
->func
->card_present(local
)) &&
719 local
->hw_ready
&& local
->ap
&& local
->iw_mode
== IW_MODE_MASTER
)
720 hostap_deauth_all_stas(dev
, local
->ap
, 1);
721 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
723 if (local
->func
->dev_close
&& local
->func
->dev_close(local
))
726 if (dev
== local
->dev
) {
727 local
->func
->hw_shutdown(dev
, HOSTAP_HW_ENABLE_CMDCOMPL
);
730 if (netif_running(dev
)) {
731 netif_stop_queue(dev
);
732 netif_device_detach(dev
);
735 flush_scheduled_work();
737 module_put(local
->hw_module
);
739 local
->num_dev_open
--;
741 if (dev
!= local
->dev
&& local
->dev
->flags
& IFF_UP
&&
742 local
->master_dev_auto_open
&& local
->num_dev_open
== 1) {
743 /* Close master radio interface automatically if it was also
744 * opened automatically and we are now closing the last
745 * remaining non-master device. */
746 dev_close(local
->dev
);
753 static int prism2_open(struct net_device
*dev
)
755 struct hostap_interface
*iface
;
758 PDEBUG(DEBUG_FLOW
, "%s: prism2_open\n", dev
->name
);
760 iface
= netdev_priv(dev
);
761 local
= iface
->local
;
764 printk(KERN_DEBUG
"%s: could not set interface UP - no PRI "
769 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
770 local
->hw_downloading
)
773 if (local
->func
->dev_open
&& local
->func
->dev_open(local
))
776 if (!try_module_get(local
->hw_module
))
778 local
->num_dev_open
++;
780 if (!local
->dev_enabled
&& local
->func
->hw_enable(dev
, 1)) {
781 printk(KERN_WARNING
"%s: could not enable MAC port\n",
786 if (!local
->dev_enabled
)
787 prism2_callback(local
, PRISM2_CALLBACK_ENABLE
);
788 local
->dev_enabled
= 1;
790 if (dev
!= local
->dev
&& !(local
->dev
->flags
& IFF_UP
)) {
791 /* Master radio interface is needed for all operation, so open
792 * it automatically when any virtual net_device is opened. */
793 local
->master_dev_auto_open
= 1;
794 dev_open(local
->dev
);
797 netif_device_attach(dev
);
798 netif_start_queue(dev
);
804 static int prism2_set_mac_address(struct net_device
*dev
, void *p
)
806 struct hostap_interface
*iface
;
808 struct list_head
*ptr
;
809 struct sockaddr
*addr
= p
;
811 iface
= netdev_priv(dev
);
812 local
= iface
->local
;
814 if (local
->func
->set_rid(dev
, HFA384X_RID_CNFOWNMACADDR
, addr
->sa_data
,
815 ETH_ALEN
) < 0 || local
->func
->reset_port(dev
))
818 read_lock_bh(&local
->iface_lock
);
819 list_for_each(ptr
, &local
->hostap_interfaces
) {
820 iface
= list_entry(ptr
, struct hostap_interface
, list
);
821 memcpy(iface
->dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
823 memcpy(local
->dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
824 read_unlock_bh(&local
->iface_lock
);
830 /* TODO: to be further implemented as soon as Prism2 fully supports
831 * GroupAddresses and correct documentation is available */
832 void hostap_set_multicast_list_queue(void *data
)
834 struct net_device
*dev
= (struct net_device
*) data
;
835 struct hostap_interface
*iface
;
838 iface
= netdev_priv(dev
);
839 local
= iface
->local
;
840 if (hostap_set_word(dev
, HFA384X_RID_PROMISCUOUSMODE
,
841 local
->is_promisc
)) {
842 printk(KERN_INFO
"%s: %sabling promiscuous mode failed\n",
843 dev
->name
, local
->is_promisc
? "en" : "dis");
848 static void hostap_set_multicast_list(struct net_device
*dev
)
851 /* FIX: promiscuous mode seems to be causing a lot of problems with
852 * some station firmware versions (FCSErr frames, invalid MACPort, etc.
853 * corrupted incoming frames). This code is now commented out while the
854 * problems are investigated. */
855 struct hostap_interface
*iface
;
858 iface
= netdev_priv(dev
);
859 local
= iface
->local
;
860 if ((dev
->flags
& IFF_ALLMULTI
) || (dev
->flags
& IFF_PROMISC
)) {
861 local
->is_promisc
= 1;
863 local
->is_promisc
= 0;
866 schedule_work(&local
->set_multicast_list_queue
);
871 static int prism2_change_mtu(struct net_device
*dev
, int new_mtu
)
873 if (new_mtu
< PRISM2_MIN_MTU
|| new_mtu
> PRISM2_MAX_MTU
)
881 static void prism2_tx_timeout(struct net_device
*dev
)
883 struct hostap_interface
*iface
;
885 struct hfa384x_regs regs
;
887 iface
= netdev_priv(dev
);
888 local
= iface
->local
;
890 printk(KERN_WARNING
"%s Tx timed out! Resetting card\n", dev
->name
);
891 netif_stop_queue(local
->dev
);
893 local
->func
->read_regs(dev
, ®s
);
894 printk(KERN_DEBUG
"%s: CMD=%04x EVSTAT=%04x "
895 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
896 dev
->name
, regs
.cmd
, regs
.evstat
, regs
.offset0
, regs
.offset1
,
899 local
->func
->schedule_reset(local
);
903 void hostap_setup_dev(struct net_device
*dev
, local_info_t
*local
,
906 struct hostap_interface
*iface
;
908 iface
= netdev_priv(dev
);
911 /* kernel callbacks */
912 dev
->get_stats
= hostap_get_stats
;
914 /* Currently, we point to the proper spy_data only on
915 * the main_dev. This could be fixed. Jean II */
916 iface
->wireless_data
.spy_data
= &iface
->spy_data
;
917 dev
->wireless_data
= &iface
->wireless_data
;
919 dev
->wireless_handlers
=
920 (struct iw_handler_def
*) &hostap_iw_handler_def
;
921 dev
->do_ioctl
= hostap_ioctl
;
922 dev
->open
= prism2_open
;
923 dev
->stop
= prism2_close
;
924 dev
->hard_start_xmit
= hostap_data_start_xmit
;
925 dev
->set_mac_address
= prism2_set_mac_address
;
926 dev
->set_multicast_list
= hostap_set_multicast_list
;
927 dev
->change_mtu
= prism2_change_mtu
;
928 dev
->tx_timeout
= prism2_tx_timeout
;
929 dev
->watchdog_timeo
= TX_TIMEOUT
;
931 dev
->mtu
= local
->mtu
;
933 /* use main radio device queue */
934 dev
->tx_queue_len
= 0;
937 SET_ETHTOOL_OPS(dev
, &prism2_ethtool_ops
);
939 netif_stop_queue(dev
);
943 static int hostap_enable_hostapd(local_info_t
*local
, int rtnl_locked
)
945 struct net_device
*dev
= local
->dev
;
950 printk(KERN_DEBUG
"%s: enabling hostapd mode\n", dev
->name
);
952 local
->apdev
= hostap_add_interface(local
, HOSTAP_INTERFACE_AP
,
953 rtnl_locked
, local
->ddev
->name
,
955 if (local
->apdev
== NULL
)
958 local
->apdev
->hard_start_xmit
= hostap_mgmt_start_xmit
;
959 local
->apdev
->type
= ARPHRD_IEEE80211
;
960 local
->apdev
->hard_header_parse
= hostap_80211_header_parse
;
966 static int hostap_disable_hostapd(local_info_t
*local
, int rtnl_locked
)
968 struct net_device
*dev
= local
->dev
;
970 printk(KERN_DEBUG
"%s: disabling hostapd mode\n", dev
->name
);
972 hostap_remove_interface(local
->apdev
, rtnl_locked
, 1);
979 static int hostap_enable_hostapd_sta(local_info_t
*local
, int rtnl_locked
)
981 struct net_device
*dev
= local
->dev
;
986 printk(KERN_DEBUG
"%s: enabling hostapd STA mode\n", dev
->name
);
988 local
->stadev
= hostap_add_interface(local
, HOSTAP_INTERFACE_STA
,
989 rtnl_locked
, local
->ddev
->name
,
991 if (local
->stadev
== NULL
)
998 static int hostap_disable_hostapd_sta(local_info_t
*local
, int rtnl_locked
)
1000 struct net_device
*dev
= local
->dev
;
1002 printk(KERN_DEBUG
"%s: disabling hostapd mode\n", dev
->name
);
1004 hostap_remove_interface(local
->stadev
, rtnl_locked
, 1);
1005 local
->stadev
= NULL
;
1011 int hostap_set_hostapd(local_info_t
*local
, int val
, int rtnl_locked
)
1015 if (val
< 0 || val
> 1)
1018 if (local
->hostapd
== val
)
1022 ret
= hostap_enable_hostapd(local
, rtnl_locked
);
1027 ret
= hostap_disable_hostapd(local
, rtnl_locked
);
1036 int hostap_set_hostapd_sta(local_info_t
*local
, int val
, int rtnl_locked
)
1040 if (val
< 0 || val
> 1)
1043 if (local
->hostapd_sta
== val
)
1047 ret
= hostap_enable_hostapd_sta(local
, rtnl_locked
);
1049 local
->hostapd_sta
= 1;
1051 local
->hostapd_sta
= 0;
1052 ret
= hostap_disable_hostapd_sta(local
, rtnl_locked
);
1054 local
->hostapd_sta
= 1;
1062 int prism2_update_comms_qual(struct net_device
*dev
)
1064 struct hostap_interface
*iface
;
1065 local_info_t
*local
;
1067 struct hfa384x_comms_quality sq
;
1069 iface
= netdev_priv(dev
);
1070 local
= iface
->local
;
1071 if (!local
->sta_fw_ver
)
1073 else if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,3,1)) {
1074 if (local
->func
->get_rid(local
->dev
,
1075 HFA384X_RID_DBMCOMMSQUALITY
,
1076 &sq
, sizeof(sq
), 1) >= 0) {
1077 local
->comms_qual
= (s16
) le16_to_cpu(sq
.comm_qual
);
1078 local
->avg_signal
= (s16
) le16_to_cpu(sq
.signal_level
);
1079 local
->avg_noise
= (s16
) le16_to_cpu(sq
.noise_level
);
1080 local
->last_comms_qual_update
= jiffies
;
1084 if (local
->func
->get_rid(local
->dev
, HFA384X_RID_COMMSQUALITY
,
1085 &sq
, sizeof(sq
), 1) >= 0) {
1086 local
->comms_qual
= le16_to_cpu(sq
.comm_qual
);
1087 local
->avg_signal
= HFA384X_LEVEL_TO_dBm(
1088 le16_to_cpu(sq
.signal_level
));
1089 local
->avg_noise
= HFA384X_LEVEL_TO_dBm(
1090 le16_to_cpu(sq
.noise_level
));
1091 local
->last_comms_qual_update
= jiffies
;
1100 int prism2_sta_send_mgmt(local_info_t
*local
, u8
*dst
, u8 stype
,
1101 u8
*body
, size_t bodylen
)
1103 struct sk_buff
*skb
;
1104 struct hostap_ieee80211_mgmt
*mgmt
;
1105 struct hostap_skb_tx_data
*meta
;
1106 struct net_device
*dev
= local
->dev
;
1108 skb
= dev_alloc_skb(IEEE80211_MGMT_HDR_LEN
+ bodylen
);
1112 mgmt
= (struct hostap_ieee80211_mgmt
*)
1113 skb_put(skb
, IEEE80211_MGMT_HDR_LEN
);
1114 memset(mgmt
, 0, IEEE80211_MGMT_HDR_LEN
);
1115 mgmt
->frame_control
=
1116 cpu_to_le16((WLAN_FC_TYPE_MGMT
<< 2) | (stype
<< 4));
1117 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
1118 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1119 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
1121 memcpy(skb_put(skb
, bodylen
), body
, bodylen
);
1123 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1124 memset(meta
, 0, sizeof(*meta
));
1125 meta
->magic
= HOSTAP_SKB_TX_DATA_MAGIC
;
1126 meta
->iface
= netdev_priv(dev
);
1129 skb
->mac
.raw
= skb
->nh
.raw
= skb
->data
;
1130 dev_queue_xmit(skb
);
1136 int prism2_sta_deauth(local_info_t
*local
, u16 reason
)
1138 union iwreq_data wrqu
;
1141 if (local
->iw_mode
!= IW_MODE_INFRA
||
1142 memcmp(local
->bssid
, "\x00\x00\x00\x00\x00\x00", ETH_ALEN
) == 0 ||
1143 memcmp(local
->bssid
, "\x44\x44\x44\x44\x44\x44", ETH_ALEN
) == 0)
1146 reason
= cpu_to_le16(reason
);
1147 ret
= prism2_sta_send_mgmt(local
, local
->bssid
, WLAN_FC_STYPE_DEAUTH
,
1149 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
1150 wireless_send_event(local
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
1155 struct proc_dir_entry
*hostap_proc
;
1157 static int __init
hostap_init(void)
1159 hostap_crypto_init();
1161 if (proc_net
!= NULL
) {
1162 hostap_proc
= proc_mkdir("hostap", proc_net
);
1164 printk(KERN_WARNING
"Failed to mkdir "
1165 "/proc/net/hostap\n");
1173 static void __exit
hostap_exit(void)
1175 if (hostap_proc
!= NULL
) {
1177 remove_proc_entry("hostap", proc_net
);
1180 hostap_crypto_deinit();
1184 EXPORT_SYMBOL(hostap_set_word
);
1185 EXPORT_SYMBOL(hostap_set_string
);
1186 EXPORT_SYMBOL(hostap_get_porttype
);
1187 EXPORT_SYMBOL(hostap_set_encryption
);
1188 EXPORT_SYMBOL(hostap_set_antsel
);
1189 EXPORT_SYMBOL(hostap_set_roaming
);
1190 EXPORT_SYMBOL(hostap_set_auth_algs
);
1191 EXPORT_SYMBOL(hostap_dump_rx_header
);
1192 EXPORT_SYMBOL(hostap_dump_tx_header
);
1193 EXPORT_SYMBOL(hostap_80211_header_parse
);
1194 EXPORT_SYMBOL(hostap_80211_prism_header_parse
);
1195 EXPORT_SYMBOL(hostap_80211_get_hdrlen
);
1196 EXPORT_SYMBOL(hostap_get_stats
);
1197 EXPORT_SYMBOL(hostap_setup_dev
);
1198 EXPORT_SYMBOL(hostap_proc
);
1199 EXPORT_SYMBOL(hostap_set_multicast_list_queue
);
1200 EXPORT_SYMBOL(hostap_set_hostapd
);
1201 EXPORT_SYMBOL(hostap_set_hostapd_sta
);
1202 EXPORT_SYMBOL(hostap_add_interface
);
1203 EXPORT_SYMBOL(hostap_remove_interface
);
1204 EXPORT_SYMBOL(prism2_update_comms_qual
);
1206 module_init(hostap_init
);
1207 module_exit(hostap_exit
);