1 // SPDX-License-Identifier: GPL-2.0-only
3 * Host AP (software wireless LAN access point) driver for
4 * Intersil Prism2/2.5/3 - hostap.o module, common routines
6 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
8 * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/proc_fs.h>
15 #include <linux/if_arp.h>
16 #include <linux/delay.h>
17 #include <linux/random.h>
18 #include <linux/workqueue.h>
19 #include <linux/kmod.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/wireless.h>
22 #include <linux/etherdevice.h>
23 #include <net/net_namespace.h>
24 #include <net/iw_handler.h>
25 #include <net/lib80211.h>
26 #include <linux/uaccess.h>
28 #include "hostap_wlan.h"
29 #include "hostap_80211.h"
30 #include "hostap_ap.h"
33 MODULE_AUTHOR("Jouni Malinen");
34 MODULE_DESCRIPTION("Host AP common routines");
35 MODULE_LICENSE("GPL");
37 #define TX_TIMEOUT (2 * HZ)
39 #define PRISM2_MAX_FRAME_SIZE 2304
40 #define PRISM2_MIN_MTU 256
42 #define PRISM2_MAX_MTU (PRISM2_MAX_FRAME_SIZE - (6 /* LLC */ + 8 /* WEP */))
45 struct net_device
* hostap_add_interface(struct local_info
*local
,
46 int type
, int rtnl_locked
,
50 struct net_device
*dev
, *mdev
;
51 struct hostap_interface
*iface
;
54 dev
= alloc_etherdev(sizeof(struct hostap_interface
));
58 iface
= netdev_priv(dev
);
62 list_add(&iface
->list
, &local
->hostap_interfaces
);
65 eth_hw_addr_inherit(dev
, mdev
);
66 dev
->base_addr
= mdev
->base_addr
;
68 dev
->mem_start
= mdev
->mem_start
;
69 dev
->mem_end
= mdev
->mem_end
;
71 hostap_setup_dev(dev
, local
, type
);
72 dev
->needs_free_netdev
= true;
74 sprintf(dev
->name
, "%s%s", prefix
, name
);
78 SET_NETDEV_DEV(dev
, mdev
->dev
.parent
);
79 ret
= register_netdevice(dev
);
85 printk(KERN_WARNING
"%s: failed to add new netdevice!\n",
91 printk(KERN_DEBUG
"%s: registered netdevice %s\n",
92 mdev
->name
, dev
->name
);
98 void hostap_remove_interface(struct net_device
*dev
, int rtnl_locked
,
101 struct hostap_interface
*iface
;
106 iface
= netdev_priv(dev
);
108 if (remove_from_list
) {
109 list_del(&iface
->list
);
112 if (dev
== iface
->local
->ddev
)
113 iface
->local
->ddev
= NULL
;
114 else if (dev
== iface
->local
->apdev
)
115 iface
->local
->apdev
= NULL
;
116 else if (dev
== iface
->local
->stadev
)
117 iface
->local
->stadev
= NULL
;
120 unregister_netdevice(dev
);
122 unregister_netdev(dev
);
124 /* 'dev->needs_free_netdev = true' implies device data, including
125 * private data, will be freed when the device is removed */
129 static inline int prism2_wds_special_addr(u8
*addr
)
131 if (addr
[0] || addr
[1] || addr
[2] || addr
[3] || addr
[4] || addr
[5])
138 int prism2_wds_add(local_info_t
*local
, u8
*remote_addr
,
141 struct net_device
*dev
;
142 struct list_head
*ptr
;
143 struct hostap_interface
*iface
, *empty
, *match
;
145 empty
= match
= NULL
;
146 read_lock_bh(&local
->iface_lock
);
147 list_for_each(ptr
, &local
->hostap_interfaces
) {
148 iface
= list_entry(ptr
, struct hostap_interface
, list
);
149 if (iface
->type
!= HOSTAP_INTERFACE_WDS
)
152 if (prism2_wds_special_addr(iface
->u
.wds
.remote_addr
))
154 else if (ether_addr_equal(iface
->u
.wds
.remote_addr
, remote_addr
)) {
159 if (!match
&& empty
&& !prism2_wds_special_addr(remote_addr
)) {
160 /* take pre-allocated entry into use */
161 memcpy(empty
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
162 read_unlock_bh(&local
->iface_lock
);
163 printk(KERN_DEBUG
"%s: using pre-allocated WDS netdevice %s\n",
164 local
->dev
->name
, empty
->dev
->name
);
167 read_unlock_bh(&local
->iface_lock
);
169 if (!prism2_wds_special_addr(remote_addr
)) {
172 hostap_add_sta(local
->ap
, remote_addr
);
175 if (local
->wds_connections
>= local
->wds_max_connections
)
178 /* verify that there is room for wds# postfix in the interface name */
179 if (strlen(local
->dev
->name
) >= IFNAMSIZ
- 5) {
180 printk(KERN_DEBUG
"'%s' too long base device name\n",
185 dev
= hostap_add_interface(local
, HOSTAP_INTERFACE_WDS
, rtnl_locked
,
186 local
->ddev
->name
, "wds%d");
190 iface
= netdev_priv(dev
);
191 memcpy(iface
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
193 local
->wds_connections
++;
199 int prism2_wds_del(local_info_t
*local
, u8
*remote_addr
,
200 int rtnl_locked
, int do_not_remove
)
203 struct list_head
*ptr
;
204 struct hostap_interface
*iface
, *selected
= NULL
;
206 write_lock_irqsave(&local
->iface_lock
, flags
);
207 list_for_each(ptr
, &local
->hostap_interfaces
) {
208 iface
= list_entry(ptr
, struct hostap_interface
, list
);
209 if (iface
->type
!= HOSTAP_INTERFACE_WDS
)
212 if (ether_addr_equal(iface
->u
.wds
.remote_addr
, remote_addr
)) {
217 if (selected
&& !do_not_remove
)
218 list_del(&selected
->list
);
219 write_unlock_irqrestore(&local
->iface_lock
, flags
);
223 eth_zero_addr(selected
->u
.wds
.remote_addr
);
225 hostap_remove_interface(selected
->dev
, rtnl_locked
, 0);
226 local
->wds_connections
--;
230 return selected
? 0 : -ENODEV
;
234 u16
hostap_tx_callback_register(local_info_t
*local
,
235 void (*func
)(struct sk_buff
*, int ok
, void *),
239 struct hostap_tx_callback_info
*entry
;
241 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
248 spin_lock_irqsave(&local
->lock
, flags
);
249 entry
->idx
= local
->tx_callback
? local
->tx_callback
->idx
+ 1 : 1;
250 entry
->next
= local
->tx_callback
;
251 local
->tx_callback
= entry
;
252 spin_unlock_irqrestore(&local
->lock
, flags
);
258 int hostap_tx_callback_unregister(local_info_t
*local
, u16 idx
)
261 struct hostap_tx_callback_info
*cb
, *prev
= NULL
;
263 spin_lock_irqsave(&local
->lock
, flags
);
264 cb
= local
->tx_callback
;
265 while (cb
!= NULL
&& cb
->idx
!= idx
) {
271 local
->tx_callback
= cb
->next
;
273 prev
->next
= cb
->next
;
276 spin_unlock_irqrestore(&local
->lock
, flags
);
282 /* val is in host byte order */
283 int hostap_set_word(struct net_device
*dev
, int rid
, u16 val
)
285 struct hostap_interface
*iface
;
286 __le16 tmp
= cpu_to_le16(val
);
287 iface
= netdev_priv(dev
);
288 return iface
->local
->func
->set_rid(dev
, rid
, &tmp
, 2);
292 int hostap_set_string(struct net_device
*dev
, int rid
, const char *val
)
294 struct hostap_interface
*iface
;
295 char buf
[MAX_SSID_LEN
+ 2];
298 iface
= netdev_priv(dev
);
300 if (len
> MAX_SSID_LEN
)
302 memset(buf
, 0, sizeof(buf
));
303 buf
[0] = len
; /* little endian 16 bit word */
304 memcpy(buf
+ 2, val
, len
);
306 return iface
->local
->func
->set_rid(dev
, rid
, &buf
, MAX_SSID_LEN
+ 2);
310 u16
hostap_get_porttype(local_info_t
*local
)
312 if (local
->iw_mode
== IW_MODE_ADHOC
&& local
->pseudo_adhoc
)
313 return HFA384X_PORTTYPE_PSEUDO_IBSS
;
314 if (local
->iw_mode
== IW_MODE_ADHOC
)
315 return HFA384X_PORTTYPE_IBSS
;
316 if (local
->iw_mode
== IW_MODE_INFRA
)
317 return HFA384X_PORTTYPE_BSS
;
318 if (local
->iw_mode
== IW_MODE_REPEAT
)
319 return HFA384X_PORTTYPE_WDS
;
320 if (local
->iw_mode
== IW_MODE_MONITOR
)
321 return HFA384X_PORTTYPE_PSEUDO_IBSS
;
322 return HFA384X_PORTTYPE_HOSTAP
;
326 int hostap_set_encryption(local_info_t
*local
)
329 int i
, keylen
, len
, idx
;
330 char keybuf
[WEP_KEY_LEN
+ 1];
331 enum { NONE
, WEP
, OTHER
} encrypt_type
;
333 idx
= local
->crypt_info
.tx_keyidx
;
334 if (local
->crypt_info
.crypt
[idx
] == NULL
||
335 local
->crypt_info
.crypt
[idx
]->ops
== NULL
)
337 else if (strcmp(local
->crypt_info
.crypt
[idx
]->ops
->name
, "WEP") == 0)
340 encrypt_type
= OTHER
;
342 if (local
->func
->get_rid(local
->dev
, HFA384X_RID_CNFWEPFLAGS
, &val
, 2,
344 printk(KERN_DEBUG
"Could not read current WEP flags.\n");
350 if (encrypt_type
!= NONE
|| local
->privacy_invoked
)
351 val
|= HFA384X_WEPFLAGS_PRIVACYINVOKED
;
353 val
&= ~HFA384X_WEPFLAGS_PRIVACYINVOKED
;
355 if (local
->open_wep
|| encrypt_type
== NONE
||
356 ((local
->ieee_802_1x
|| local
->wpa
) && local
->host_decrypt
))
357 val
&= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED
;
359 val
|= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED
;
361 if ((encrypt_type
!= NONE
|| local
->privacy_invoked
) &&
362 (encrypt_type
== OTHER
|| local
->host_encrypt
))
363 val
|= HFA384X_WEPFLAGS_HOSTENCRYPT
;
365 val
&= ~HFA384X_WEPFLAGS_HOSTENCRYPT
;
366 if ((encrypt_type
!= NONE
|| local
->privacy_invoked
) &&
367 (encrypt_type
== OTHER
|| local
->host_decrypt
))
368 val
|= HFA384X_WEPFLAGS_HOSTDECRYPT
;
370 val
&= ~HFA384X_WEPFLAGS_HOSTDECRYPT
;
372 if (val
!= old_val
&&
373 hostap_set_word(local
->dev
, HFA384X_RID_CNFWEPFLAGS
, val
)) {
374 printk(KERN_DEBUG
"Could not write new WEP flags (0x%x)\n",
379 if (encrypt_type
!= WEP
)
382 /* 104-bit support seems to require that all the keys are set to the
384 keylen
= 6; /* first 5 octets */
385 len
= local
->crypt_info
.crypt
[idx
]->ops
->get_key(keybuf
, sizeof(keybuf
), NULL
,
386 local
->crypt_info
.crypt
[idx
]->priv
);
387 if (idx
>= 0 && idx
< WEP_KEYS
&& len
> 5)
388 keylen
= WEP_KEY_LEN
+ 1; /* first 13 octets */
390 for (i
= 0; i
< WEP_KEYS
; i
++) {
391 memset(keybuf
, 0, sizeof(keybuf
));
392 if (local
->crypt_info
.crypt
[i
]) {
393 (void) local
->crypt_info
.crypt
[i
]->ops
->get_key(
394 keybuf
, sizeof(keybuf
),
395 NULL
, local
->crypt_info
.crypt
[i
]->priv
);
397 if (local
->func
->set_rid(local
->dev
,
398 HFA384X_RID_CNFDEFAULTKEY0
+ i
,
400 printk(KERN_DEBUG
"Could not set key %d (len=%d)\n",
405 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFWEPDEFAULTKEYID
, idx
)) {
406 printk(KERN_DEBUG
"Could not set default keyid %d\n", idx
);
413 printk(KERN_DEBUG
"%s: encryption setup failed\n", local
->dev
->name
);
418 int hostap_set_antsel(local_info_t
*local
)
423 if (local
->antsel_tx
!= HOSTAP_ANTSEL_DO_NOT_TOUCH
&&
424 local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_READMIF
,
425 HFA386X_CR_TX_CONFIGURE
,
427 val
&= ~(BIT(2) | BIT(1));
428 switch (local
->antsel_tx
) {
429 case HOSTAP_ANTSEL_DIVERSITY
:
432 case HOSTAP_ANTSEL_LOW
:
434 case HOSTAP_ANTSEL_HIGH
:
439 if (local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_WRITEMIF
,
440 HFA386X_CR_TX_CONFIGURE
, &val
, NULL
)) {
441 printk(KERN_INFO
"%s: setting TX AntSel failed\n",
447 if (local
->antsel_rx
!= HOSTAP_ANTSEL_DO_NOT_TOUCH
&&
448 local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_READMIF
,
449 HFA386X_CR_RX_CONFIGURE
,
451 val
&= ~(BIT(1) | BIT(0));
452 switch (local
->antsel_rx
) {
453 case HOSTAP_ANTSEL_DIVERSITY
:
455 case HOSTAP_ANTSEL_LOW
:
458 case HOSTAP_ANTSEL_HIGH
:
459 val
|= BIT(0) | BIT(1);
463 if (local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_WRITEMIF
,
464 HFA386X_CR_RX_CONFIGURE
, &val
, NULL
)) {
465 printk(KERN_INFO
"%s: setting RX AntSel failed\n",
475 int hostap_set_roaming(local_info_t
*local
)
479 switch (local
->host_roaming
) {
481 val
= HFA384X_ROAMING_HOST
;
484 val
= HFA384X_ROAMING_DISABLED
;
488 val
= HFA384X_ROAMING_FIRMWARE
;
492 return hostap_set_word(local
->dev
, HFA384X_RID_CNFROAMINGMODE
, val
);
496 int hostap_set_auth_algs(local_info_t
*local
)
498 int val
= local
->auth_algs
;
499 /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication
500 * set to include both Open and Shared Key flags. It tries to use
501 * Shared Key authentication in that case even if WEP keys are not
502 * configured.. STA f/w v0.7.6 is able to handle such configuration,
503 * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */
504 if (local
->sta_fw_ver
< PRISM2_FW_VER(0,7,0) &&
505 val
!= PRISM2_AUTH_OPEN
&& val
!= PRISM2_AUTH_SHARED_KEY
)
506 val
= PRISM2_AUTH_OPEN
;
508 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFAUTHENTICATION
, val
)) {
509 printk(KERN_INFO
"%s: cnfAuthentication setting to 0x%x "
510 "failed\n", local
->dev
->name
, local
->auth_algs
);
518 void hostap_dump_rx_header(const char *name
, const struct hfa384x_rx_frame
*rx
)
522 status
= __le16_to_cpu(rx
->status
);
524 printk(KERN_DEBUG
"%s: RX status=0x%04x (port=%d, type=%d, "
525 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
527 name
, status
, (status
>> 8) & 0x07, status
>> 13, status
& 1,
528 rx
->silence
, rx
->signal
, rx
->rate
, rx
->rxflow
, jiffies
);
530 fc
= __le16_to_cpu(rx
->frame_control
);
531 printk(KERN_DEBUG
" FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
533 fc
, (fc
& IEEE80211_FCTL_FTYPE
) >> 2,
534 (fc
& IEEE80211_FCTL_STYPE
) >> 4,
535 __le16_to_cpu(rx
->duration_id
), __le16_to_cpu(rx
->seq_ctrl
),
536 __le16_to_cpu(rx
->data_len
),
537 fc
& IEEE80211_FCTL_TODS
? " [ToDS]" : "",
538 fc
& IEEE80211_FCTL_FROMDS
? " [FromDS]" : "");
540 printk(KERN_DEBUG
" A1=%pM A2=%pM A3=%pM A4=%pM\n",
541 rx
->addr1
, rx
->addr2
, rx
->addr3
, rx
->addr4
);
543 printk(KERN_DEBUG
" dst=%pM src=%pM len=%d\n",
544 rx
->dst_addr
, rx
->src_addr
,
545 __be16_to_cpu(rx
->len
));
549 void hostap_dump_tx_header(const char *name
, const struct hfa384x_tx_frame
*tx
)
553 printk(KERN_DEBUG
"%s: TX status=0x%04x retry_count=%d tx_rate=%d "
554 "tx_control=0x%04x; jiffies=%ld\n",
555 name
, __le16_to_cpu(tx
->status
), tx
->retry_count
, tx
->tx_rate
,
556 __le16_to_cpu(tx
->tx_control
), jiffies
);
558 fc
= __le16_to_cpu(tx
->frame_control
);
559 printk(KERN_DEBUG
" FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
561 fc
, (fc
& IEEE80211_FCTL_FTYPE
) >> 2,
562 (fc
& IEEE80211_FCTL_STYPE
) >> 4,
563 __le16_to_cpu(tx
->duration_id
), __le16_to_cpu(tx
->seq_ctrl
),
564 __le16_to_cpu(tx
->data_len
),
565 fc
& IEEE80211_FCTL_TODS
? " [ToDS]" : "",
566 fc
& IEEE80211_FCTL_FROMDS
? " [FromDS]" : "");
568 printk(KERN_DEBUG
" A1=%pM A2=%pM A3=%pM A4=%pM\n",
569 tx
->addr1
, tx
->addr2
, tx
->addr3
, tx
->addr4
);
571 printk(KERN_DEBUG
" dst=%pM src=%pM len=%d\n",
572 tx
->dst_addr
, tx
->src_addr
,
573 __be16_to_cpu(tx
->len
));
577 static int hostap_80211_header_parse(const struct sk_buff
*skb
,
578 unsigned char *haddr
)
580 memcpy(haddr
, skb_mac_header(skb
) + 10, ETH_ALEN
); /* addr2 */
585 int hostap_80211_get_hdrlen(__le16 fc
)
587 if (ieee80211_is_data(fc
) && ieee80211_has_a4 (fc
))
588 return 30; /* Addr4 */
589 else if (ieee80211_is_cts(fc
) || ieee80211_is_ack(fc
))
591 else if (ieee80211_is_ctl(fc
))
598 static int prism2_close(struct net_device
*dev
)
600 struct hostap_interface
*iface
;
603 PDEBUG(DEBUG_FLOW
, "%s: prism2_close\n", dev
->name
);
605 iface
= netdev_priv(dev
);
606 local
= iface
->local
;
608 if (dev
== local
->ddev
) {
609 prism2_sta_deauth(local
, WLAN_REASON_DEAUTH_LEAVING
);
611 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
612 if (!local
->hostapd
&& dev
== local
->dev
&&
613 (!local
->func
->card_present
|| local
->func
->card_present(local
)) &&
614 local
->hw_ready
&& local
->ap
&& local
->iw_mode
== IW_MODE_MASTER
)
615 hostap_deauth_all_stas(dev
, local
->ap
, 1);
616 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
618 if (dev
== local
->dev
) {
619 local
->func
->hw_shutdown(dev
, HOSTAP_HW_ENABLE_CMDCOMPL
);
622 if (netif_running(dev
)) {
623 netif_stop_queue(dev
);
624 netif_device_detach(dev
);
627 cancel_work_sync(&local
->reset_queue
);
628 cancel_work_sync(&local
->set_multicast_list_queue
);
629 cancel_work_sync(&local
->set_tim_queue
);
630 #ifndef PRISM2_NO_STATION_MODES
631 cancel_work_sync(&local
->info_queue
);
633 cancel_work_sync(&local
->comms_qual_update
);
635 module_put(local
->hw_module
);
637 local
->num_dev_open
--;
639 if (dev
!= local
->dev
&& local
->dev
->flags
& IFF_UP
&&
640 local
->master_dev_auto_open
&& local
->num_dev_open
== 1) {
641 /* Close master radio interface automatically if it was also
642 * opened automatically and we are now closing the last
643 * remaining non-master device. */
644 dev_close(local
->dev
);
651 static int prism2_open(struct net_device
*dev
)
653 struct hostap_interface
*iface
;
656 PDEBUG(DEBUG_FLOW
, "%s: prism2_open\n", dev
->name
);
658 iface
= netdev_priv(dev
);
659 local
= iface
->local
;
662 printk(KERN_DEBUG
"%s: could not set interface UP - no PRI "
667 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
668 local
->hw_downloading
)
671 if (!try_module_get(local
->hw_module
))
673 local
->num_dev_open
++;
675 if (!local
->dev_enabled
&& local
->func
->hw_enable(dev
, 1)) {
676 printk(KERN_WARNING
"%s: could not enable MAC port\n",
681 if (!local
->dev_enabled
)
682 prism2_callback(local
, PRISM2_CALLBACK_ENABLE
);
683 local
->dev_enabled
= 1;
685 if (dev
!= local
->dev
&& !(local
->dev
->flags
& IFF_UP
)) {
686 /* Master radio interface is needed for all operation, so open
687 * it automatically when any virtual net_device is opened. */
688 local
->master_dev_auto_open
= 1;
689 dev_open(local
->dev
, NULL
);
692 netif_device_attach(dev
);
693 netif_start_queue(dev
);
699 static int prism2_set_mac_address(struct net_device
*dev
, void *p
)
701 struct hostap_interface
*iface
;
703 struct list_head
*ptr
;
704 struct sockaddr
*addr
= p
;
706 iface
= netdev_priv(dev
);
707 local
= iface
->local
;
709 if (local
->func
->set_rid(dev
, HFA384X_RID_CNFOWNMACADDR
, addr
->sa_data
,
710 ETH_ALEN
) < 0 || local
->func
->reset_port(dev
))
713 read_lock_bh(&local
->iface_lock
);
714 list_for_each(ptr
, &local
->hostap_interfaces
) {
715 iface
= list_entry(ptr
, struct hostap_interface
, list
);
716 memcpy(iface
->dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
718 memcpy(local
->dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
719 read_unlock_bh(&local
->iface_lock
);
725 /* TODO: to be further implemented as soon as Prism2 fully supports
726 * GroupAddresses and correct documentation is available */
727 void hostap_set_multicast_list_queue(struct work_struct
*work
)
729 local_info_t
*local
=
730 container_of(work
, local_info_t
, set_multicast_list_queue
);
731 struct net_device
*dev
= local
->dev
;
733 if (hostap_set_word(dev
, HFA384X_RID_PROMISCUOUSMODE
,
734 local
->is_promisc
)) {
735 printk(KERN_INFO
"%s: %sabling promiscuous mode failed\n",
736 dev
->name
, local
->is_promisc
? "en" : "dis");
741 static void hostap_set_multicast_list(struct net_device
*dev
)
744 /* FIX: promiscuous mode seems to be causing a lot of problems with
745 * some station firmware versions (FCSErr frames, invalid MACPort, etc.
746 * corrupted incoming frames). This code is now commented out while the
747 * problems are investigated. */
748 struct hostap_interface
*iface
;
751 iface
= netdev_priv(dev
);
752 local
= iface
->local
;
753 if ((dev
->flags
& IFF_ALLMULTI
) || (dev
->flags
& IFF_PROMISC
)) {
754 local
->is_promisc
= 1;
756 local
->is_promisc
= 0;
759 schedule_work(&local
->set_multicast_list_queue
);
764 static void prism2_tx_timeout(struct net_device
*dev
, unsigned int txqueue
)
766 struct hostap_interface
*iface
;
768 struct hfa384x_regs regs
;
770 iface
= netdev_priv(dev
);
771 local
= iface
->local
;
773 printk(KERN_WARNING
"%s Tx timed out! Resetting card\n", dev
->name
);
774 netif_stop_queue(local
->dev
);
776 local
->func
->read_regs(dev
, ®s
);
777 printk(KERN_DEBUG
"%s: CMD=%04x EVSTAT=%04x "
778 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
779 dev
->name
, regs
.cmd
, regs
.evstat
, regs
.offset0
, regs
.offset1
,
782 local
->func
->schedule_reset(local
);
785 const struct header_ops hostap_80211_ops
= {
786 .create
= eth_header
,
787 .cache
= eth_header_cache
,
788 .cache_update
= eth_header_cache_update
,
789 .parse
= hostap_80211_header_parse
,
791 EXPORT_SYMBOL(hostap_80211_ops
);
794 static const struct net_device_ops hostap_netdev_ops
= {
795 .ndo_start_xmit
= hostap_data_start_xmit
,
797 .ndo_open
= prism2_open
,
798 .ndo_stop
= prism2_close
,
799 .ndo_do_ioctl
= hostap_ioctl
,
800 .ndo_set_mac_address
= prism2_set_mac_address
,
801 .ndo_set_rx_mode
= hostap_set_multicast_list
,
802 .ndo_tx_timeout
= prism2_tx_timeout
,
803 .ndo_validate_addr
= eth_validate_addr
,
806 static const struct net_device_ops hostap_mgmt_netdev_ops
= {
807 .ndo_start_xmit
= hostap_mgmt_start_xmit
,
809 .ndo_open
= prism2_open
,
810 .ndo_stop
= prism2_close
,
811 .ndo_do_ioctl
= hostap_ioctl
,
812 .ndo_set_mac_address
= prism2_set_mac_address
,
813 .ndo_set_rx_mode
= hostap_set_multicast_list
,
814 .ndo_tx_timeout
= prism2_tx_timeout
,
815 .ndo_validate_addr
= eth_validate_addr
,
818 static const struct net_device_ops hostap_master_ops
= {
819 .ndo_start_xmit
= hostap_master_start_xmit
,
821 .ndo_open
= prism2_open
,
822 .ndo_stop
= prism2_close
,
823 .ndo_do_ioctl
= hostap_ioctl
,
824 .ndo_set_mac_address
= prism2_set_mac_address
,
825 .ndo_set_rx_mode
= hostap_set_multicast_list
,
826 .ndo_tx_timeout
= prism2_tx_timeout
,
827 .ndo_validate_addr
= eth_validate_addr
,
830 void hostap_setup_dev(struct net_device
*dev
, local_info_t
*local
,
833 struct hostap_interface
*iface
;
835 iface
= netdev_priv(dev
);
837 dev
->min_mtu
= PRISM2_MIN_MTU
;
838 dev
->max_mtu
= PRISM2_MAX_MTU
;
839 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
841 /* kernel callbacks */
843 /* Currently, we point to the proper spy_data only on
844 * the main_dev. This could be fixed. Jean II */
845 iface
->wireless_data
.spy_data
= &iface
->spy_data
;
846 dev
->wireless_data
= &iface
->wireless_data
;
848 dev
->wireless_handlers
= &hostap_iw_handler_def
;
849 dev
->watchdog_timeo
= TX_TIMEOUT
;
852 case HOSTAP_INTERFACE_AP
:
853 dev
->priv_flags
|= IFF_NO_QUEUE
; /* use main radio device queue */
854 dev
->netdev_ops
= &hostap_mgmt_netdev_ops
;
855 dev
->type
= ARPHRD_IEEE80211
;
856 dev
->header_ops
= &hostap_80211_ops
;
858 case HOSTAP_INTERFACE_MASTER
:
859 dev
->netdev_ops
= &hostap_master_ops
;
862 dev
->priv_flags
|= IFF_NO_QUEUE
; /* use main radio device queue */
863 dev
->netdev_ops
= &hostap_netdev_ops
;
866 dev
->mtu
= local
->mtu
;
869 dev
->ethtool_ops
= &prism2_ethtool_ops
;
873 static int hostap_enable_hostapd(local_info_t
*local
, int rtnl_locked
)
875 struct net_device
*dev
= local
->dev
;
880 printk(KERN_DEBUG
"%s: enabling hostapd mode\n", dev
->name
);
882 local
->apdev
= hostap_add_interface(local
, HOSTAP_INTERFACE_AP
,
883 rtnl_locked
, local
->ddev
->name
,
885 if (local
->apdev
== NULL
)
892 static int hostap_disable_hostapd(local_info_t
*local
, int rtnl_locked
)
894 struct net_device
*dev
= local
->dev
;
896 printk(KERN_DEBUG
"%s: disabling hostapd mode\n", dev
->name
);
898 hostap_remove_interface(local
->apdev
, rtnl_locked
, 1);
905 static int hostap_enable_hostapd_sta(local_info_t
*local
, int rtnl_locked
)
907 struct net_device
*dev
= local
->dev
;
912 printk(KERN_DEBUG
"%s: enabling hostapd STA mode\n", dev
->name
);
914 local
->stadev
= hostap_add_interface(local
, HOSTAP_INTERFACE_STA
,
915 rtnl_locked
, local
->ddev
->name
,
917 if (local
->stadev
== NULL
)
924 static int hostap_disable_hostapd_sta(local_info_t
*local
, int rtnl_locked
)
926 struct net_device
*dev
= local
->dev
;
928 printk(KERN_DEBUG
"%s: disabling hostapd mode\n", dev
->name
);
930 hostap_remove_interface(local
->stadev
, rtnl_locked
, 1);
931 local
->stadev
= NULL
;
937 int hostap_set_hostapd(local_info_t
*local
, int val
, int rtnl_locked
)
941 if (val
< 0 || val
> 1)
944 if (local
->hostapd
== val
)
948 ret
= hostap_enable_hostapd(local
, rtnl_locked
);
953 ret
= hostap_disable_hostapd(local
, rtnl_locked
);
962 int hostap_set_hostapd_sta(local_info_t
*local
, int val
, int rtnl_locked
)
966 if (val
< 0 || val
> 1)
969 if (local
->hostapd_sta
== val
)
973 ret
= hostap_enable_hostapd_sta(local
, rtnl_locked
);
975 local
->hostapd_sta
= 1;
977 local
->hostapd_sta
= 0;
978 ret
= hostap_disable_hostapd_sta(local
, rtnl_locked
);
980 local
->hostapd_sta
= 1;
988 int prism2_update_comms_qual(struct net_device
*dev
)
990 struct hostap_interface
*iface
;
993 struct hfa384x_comms_quality sq
;
995 iface
= netdev_priv(dev
);
996 local
= iface
->local
;
997 if (!local
->sta_fw_ver
)
999 else if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,3,1)) {
1000 if (local
->func
->get_rid(local
->dev
,
1001 HFA384X_RID_DBMCOMMSQUALITY
,
1002 &sq
, sizeof(sq
), 1) >= 0) {
1003 local
->comms_qual
= (s16
) le16_to_cpu(sq
.comm_qual
);
1004 local
->avg_signal
= (s16
) le16_to_cpu(sq
.signal_level
);
1005 local
->avg_noise
= (s16
) le16_to_cpu(sq
.noise_level
);
1006 local
->last_comms_qual_update
= jiffies
;
1010 if (local
->func
->get_rid(local
->dev
, HFA384X_RID_COMMSQUALITY
,
1011 &sq
, sizeof(sq
), 1) >= 0) {
1012 local
->comms_qual
= le16_to_cpu(sq
.comm_qual
);
1013 local
->avg_signal
= HFA384X_LEVEL_TO_dBm(
1014 le16_to_cpu(sq
.signal_level
));
1015 local
->avg_noise
= HFA384X_LEVEL_TO_dBm(
1016 le16_to_cpu(sq
.noise_level
));
1017 local
->last_comms_qual_update
= jiffies
;
1026 int prism2_sta_send_mgmt(local_info_t
*local
, u8
*dst
, u16 stype
,
1027 u8
*body
, size_t bodylen
)
1029 struct sk_buff
*skb
;
1030 struct hostap_ieee80211_mgmt
*mgmt
;
1031 struct hostap_skb_tx_data
*meta
;
1032 struct net_device
*dev
= local
->dev
;
1034 skb
= dev_alloc_skb(IEEE80211_MGMT_HDR_LEN
+ bodylen
);
1038 mgmt
= skb_put_zero(skb
, IEEE80211_MGMT_HDR_LEN
);
1039 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
| stype
);
1040 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
1041 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1042 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
1044 skb_put_data(skb
, body
, bodylen
);
1046 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1047 memset(meta
, 0, sizeof(*meta
));
1048 meta
->magic
= HOSTAP_SKB_TX_DATA_MAGIC
;
1049 meta
->iface
= netdev_priv(dev
);
1052 skb_reset_mac_header(skb
);
1053 skb_reset_network_header(skb
);
1054 dev_queue_xmit(skb
);
1060 int prism2_sta_deauth(local_info_t
*local
, u16 reason
)
1062 union iwreq_data wrqu
;
1064 __le16 val
= cpu_to_le16(reason
);
1066 if (local
->iw_mode
!= IW_MODE_INFRA
||
1067 is_zero_ether_addr(local
->bssid
) ||
1068 ether_addr_equal(local
->bssid
, "\x44\x44\x44\x44\x44\x44"))
1071 ret
= prism2_sta_send_mgmt(local
, local
->bssid
, IEEE80211_STYPE_DEAUTH
,
1073 eth_zero_addr(wrqu
.ap_addr
.sa_data
);
1074 wireless_send_event(local
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
1079 struct proc_dir_entry
*hostap_proc
;
1081 static int __init
hostap_init(void)
1083 if (init_net
.proc_net
!= NULL
) {
1084 hostap_proc
= proc_mkdir("hostap", init_net
.proc_net
);
1086 printk(KERN_WARNING
"Failed to mkdir "
1087 "/proc/net/hostap\n");
1095 static void __exit
hostap_exit(void)
1097 if (hostap_proc
!= NULL
) {
1099 remove_proc_entry("hostap", init_net
.proc_net
);
1104 EXPORT_SYMBOL(hostap_set_word
);
1105 EXPORT_SYMBOL(hostap_set_string
);
1106 EXPORT_SYMBOL(hostap_get_porttype
);
1107 EXPORT_SYMBOL(hostap_set_encryption
);
1108 EXPORT_SYMBOL(hostap_set_antsel
);
1109 EXPORT_SYMBOL(hostap_set_roaming
);
1110 EXPORT_SYMBOL(hostap_set_auth_algs
);
1111 EXPORT_SYMBOL(hostap_dump_rx_header
);
1112 EXPORT_SYMBOL(hostap_dump_tx_header
);
1113 EXPORT_SYMBOL(hostap_80211_get_hdrlen
);
1114 EXPORT_SYMBOL(hostap_setup_dev
);
1115 EXPORT_SYMBOL(hostap_set_multicast_list_queue
);
1116 EXPORT_SYMBOL(hostap_set_hostapd
);
1117 EXPORT_SYMBOL(hostap_set_hostapd_sta
);
1118 EXPORT_SYMBOL(hostap_add_interface
);
1119 EXPORT_SYMBOL(hostap_remove_interface
);
1120 EXPORT_SYMBOL(prism2_update_comms_qual
);
1122 module_init(hostap_init
);
1123 module_exit(hostap_exit
);