Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <net/mac80211.h> |
| 12 | #include <net/ieee80211_radiotap.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/skbuff.h> |
| 19 | #include <linux/etherdevice.h> |
| 20 | #include <linux/if_arp.h> |
| 21 | #include <linux/wireless.h> |
| 22 | #include <linux/rtnetlink.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 23 | #include <linux/bitmap.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 24 | #include <net/net_namespace.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 25 | #include <net/cfg80211.h> |
| 26 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 27 | #include "ieee80211_i.h" |
| 28 | #include "ieee80211_rate.h" |
Luis Carlos Cobo | f7a9214 | 2008-02-23 15:17:18 +0100 | [diff] [blame^] | 29 | #ifdef CONFIG_MAC80211_MESH |
| 30 | #include "mesh.h" |
| 31 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 32 | #include "wep.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 33 | #include "wme.h" |
| 34 | #include "aes_ccm.h" |
| 35 | #include "ieee80211_led.h" |
Michael Wu | e0eb685 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 36 | #include "cfg.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 37 | #include "debugfs.h" |
| 38 | #include "debugfs_netdev.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 39 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 40 | #define SUPP_MCS_SET_LEN 16 |
| 41 | |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 42 | /* |
| 43 | * For seeing transmitted packets on monitor interfaces |
| 44 | * we have a radiotap header too. |
| 45 | */ |
| 46 | struct ieee80211_tx_status_rtap_hdr { |
| 47 | struct ieee80211_radiotap_header hdr; |
| 48 | __le16 tx_flags; |
| 49 | u8 data_retries; |
| 50 | } __attribute__ ((packed)); |
| 51 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 52 | /* common interface routines */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 53 | |
Stephen Hemminger | b95cce3 | 2007-09-26 22:13:38 -0700 | [diff] [blame] | 54 | static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 55 | { |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 56 | memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */ |
| 57 | return ETH_ALEN; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 60 | /* must be called under mdev tx lock */ |
| 61 | static void ieee80211_configure_filter(struct ieee80211_local *local) |
| 62 | { |
| 63 | unsigned int changed_flags; |
| 64 | unsigned int new_flags = 0; |
| 65 | |
Johannes Berg | 5391899 | 2007-09-26 15:19:47 +0200 | [diff] [blame] | 66 | if (atomic_read(&local->iff_promiscs)) |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 67 | new_flags |= FIF_PROMISC_IN_BSS; |
| 68 | |
Johannes Berg | 5391899 | 2007-09-26 15:19:47 +0200 | [diff] [blame] | 69 | if (atomic_read(&local->iff_allmultis)) |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 70 | new_flags |= FIF_ALLMULTI; |
| 71 | |
| 72 | if (local->monitors) |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 73 | new_flags |= FIF_BCN_PRBRESP_PROMISC; |
| 74 | |
| 75 | if (local->fif_fcsfail) |
| 76 | new_flags |= FIF_FCSFAIL; |
| 77 | |
| 78 | if (local->fif_plcpfail) |
| 79 | new_flags |= FIF_PLCPFAIL; |
| 80 | |
| 81 | if (local->fif_control) |
| 82 | new_flags |= FIF_CONTROL; |
| 83 | |
| 84 | if (local->fif_other_bss) |
| 85 | new_flags |= FIF_OTHER_BSS; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 86 | |
| 87 | changed_flags = local->filter_flags ^ new_flags; |
| 88 | |
| 89 | /* be a bit nasty */ |
| 90 | new_flags |= (1<<31); |
| 91 | |
| 92 | local->ops->configure_filter(local_to_hw(local), |
| 93 | changed_flags, &new_flags, |
| 94 | local->mdev->mc_count, |
| 95 | local->mdev->mc_list); |
| 96 | |
| 97 | WARN_ON(new_flags & (1<<31)); |
| 98 | |
| 99 | local->filter_flags = new_flags & ~(1<<31); |
| 100 | } |
| 101 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 102 | /* master interface */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 103 | |
| 104 | static int ieee80211_master_open(struct net_device *dev) |
| 105 | { |
| 106 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 107 | struct ieee80211_sub_if_data *sdata; |
| 108 | int res = -EOPNOTSUPP; |
| 109 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 110 | /* we hold the RTNL here so can safely walk the list */ |
| 111 | list_for_each_entry(sdata, &local->interfaces, list) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 112 | if (sdata->dev != dev && netif_running(sdata->dev)) { |
| 113 | res = 0; |
| 114 | break; |
| 115 | } |
| 116 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 117 | return res; |
| 118 | } |
| 119 | |
| 120 | static int ieee80211_master_stop(struct net_device *dev) |
| 121 | { |
| 122 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 123 | struct ieee80211_sub_if_data *sdata; |
| 124 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 125 | /* we hold the RTNL here so can safely walk the list */ |
| 126 | list_for_each_entry(sdata, &local->interfaces, list) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 127 | if (sdata->dev != dev && netif_running(sdata->dev)) |
| 128 | dev_close(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 133 | static void ieee80211_master_set_multicast_list(struct net_device *dev) |
| 134 | { |
| 135 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 136 | |
| 137 | ieee80211_configure_filter(local); |
| 138 | } |
| 139 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 140 | /* regular interfaces */ |
| 141 | |
| 142 | static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) |
| 143 | { |
Luis Carlos Cobo | f7a9214 | 2008-02-23 15:17:18 +0100 | [diff] [blame^] | 144 | int meshhdrlen; |
| 145 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 146 | |
| 147 | meshhdrlen = (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) ? 5 : 0; |
| 148 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 149 | /* FIX: what would be proper limits for MTU? |
| 150 | * This interface uses 802.3 frames. */ |
Luis Carlos Cobo | f7a9214 | 2008-02-23 15:17:18 +0100 | [diff] [blame^] | 151 | if (new_mtu < 256 || |
| 152 | new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) { |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 153 | printk(KERN_WARNING "%s: invalid MTU %d\n", |
| 154 | dev->name, new_mtu); |
| 155 | return -EINVAL; |
| 156 | } |
| 157 | |
| 158 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 159 | printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu); |
| 160 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 161 | dev->mtu = new_mtu; |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static inline int identical_mac_addr_allowed(int type1, int type2) |
| 166 | { |
| 167 | return (type1 == IEEE80211_IF_TYPE_MNTR || |
| 168 | type2 == IEEE80211_IF_TYPE_MNTR || |
| 169 | (type1 == IEEE80211_IF_TYPE_AP && |
| 170 | type2 == IEEE80211_IF_TYPE_WDS) || |
| 171 | (type1 == IEEE80211_IF_TYPE_WDS && |
| 172 | (type2 == IEEE80211_IF_TYPE_WDS || |
| 173 | type2 == IEEE80211_IF_TYPE_AP)) || |
| 174 | (type1 == IEEE80211_IF_TYPE_AP && |
| 175 | type2 == IEEE80211_IF_TYPE_VLAN) || |
| 176 | (type1 == IEEE80211_IF_TYPE_VLAN && |
| 177 | (type2 == IEEE80211_IF_TYPE_AP || |
| 178 | type2 == IEEE80211_IF_TYPE_VLAN))); |
| 179 | } |
| 180 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 181 | static int ieee80211_open(struct net_device *dev) |
| 182 | { |
| 183 | struct ieee80211_sub_if_data *sdata, *nsdata; |
| 184 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 185 | struct ieee80211_if_init_conf conf; |
| 186 | int res; |
Michael Buesch | ceffefd | 2008-02-10 14:16:52 +0100 | [diff] [blame] | 187 | bool need_hw_reconfig = 0; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 188 | |
| 189 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 190 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 191 | /* we hold the RTNL here so can safely walk the list */ |
| 192 | list_for_each_entry(nsdata, &local->interfaces, list) { |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 193 | struct net_device *ndev = nsdata->dev; |
| 194 | |
Johannes Berg | 665e8aa | 2008-02-21 01:10:07 +0100 | [diff] [blame] | 195 | if (ndev != dev && ndev != local->mdev && netif_running(ndev)) { |
| 196 | /* |
| 197 | * Allow only a single IBSS interface to be up at any |
| 198 | * time. This is restricted because beacon distribution |
| 199 | * cannot work properly if both are in the same IBSS. |
| 200 | * |
| 201 | * To remove this restriction we'd have to disallow them |
| 202 | * from setting the same SSID on different IBSS interfaces |
| 203 | * belonging to the same hardware. Then, however, we're |
| 204 | * faced with having to adopt two different TSF timers... |
| 205 | */ |
| 206 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
| 207 | nsdata->vif.type == IEEE80211_IF_TYPE_IBSS) |
| 208 | return -EBUSY; |
| 209 | |
| 210 | /* |
| 211 | * Disallow multiple IBSS/STA mode interfaces. |
| 212 | * |
| 213 | * This is a technical restriction, it is possible although |
| 214 | * most likely not IEEE 802.11 compliant to have multiple |
| 215 | * STAs with just a single hardware (the TSF timer will not |
| 216 | * be adjusted properly.) |
| 217 | * |
| 218 | * However, because mac80211 uses the master device's BSS |
| 219 | * information for each STA/IBSS interface, doing this will |
| 220 | * currently corrupt that BSS information completely, unless, |
| 221 | * a not very useful case, both STAs are associated to the |
| 222 | * same BSS. |
| 223 | * |
| 224 | * To remove this restriction, the BSS information needs to |
| 225 | * be embedded in the STA/IBSS mode sdata instead of using |
| 226 | * the master device's BSS structure. |
| 227 | */ |
| 228 | if ((sdata->vif.type == IEEE80211_IF_TYPE_STA || |
| 229 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) && |
| 230 | (nsdata->vif.type == IEEE80211_IF_TYPE_STA || |
| 231 | nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)) |
| 232 | return -EBUSY; |
| 233 | |
| 234 | /* |
| 235 | * The remaining checks are only performed for interfaces |
| 236 | * with the same MAC address. |
| 237 | */ |
| 238 | if (compare_ether_addr(dev->dev_addr, ndev->dev_addr)) |
| 239 | continue; |
| 240 | |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 241 | /* |
| 242 | * check whether it may have the same address |
| 243 | */ |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 244 | if (!identical_mac_addr_allowed(sdata->vif.type, |
| 245 | nsdata->vif.type)) |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 246 | return -ENOTUNIQ; |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 247 | |
| 248 | /* |
| 249 | * can only add VLANs to enabled APs |
| 250 | */ |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 251 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN && |
Johannes Berg | 665e8aa | 2008-02-21 01:10:07 +0100 | [diff] [blame] | 252 | nsdata->vif.type == IEEE80211_IF_TYPE_AP) |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 253 | sdata->u.vlan.ap = nsdata; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 254 | } |
| 255 | } |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 256 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 257 | switch (sdata->vif.type) { |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 258 | case IEEE80211_IF_TYPE_WDS: |
| 259 | if (is_zero_ether_addr(sdata->u.wds.remote_addr)) |
| 260 | return -ENOLINK; |
| 261 | break; |
| 262 | case IEEE80211_IF_TYPE_VLAN: |
| 263 | if (!sdata->u.vlan.ap) |
| 264 | return -ENOLINK; |
| 265 | break; |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 266 | case IEEE80211_IF_TYPE_AP: |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 267 | case IEEE80211_IF_TYPE_STA: |
| 268 | case IEEE80211_IF_TYPE_MNTR: |
| 269 | case IEEE80211_IF_TYPE_IBSS: |
Johannes Berg | 6032f93 | 2008-02-23 15:17:07 +0100 | [diff] [blame] | 270 | case IEEE80211_IF_TYPE_MESH_POINT: |
Johannes Berg | fb1c1cd | 2007-09-26 15:19:43 +0200 | [diff] [blame] | 271 | /* no special treatment */ |
| 272 | break; |
Johannes Berg | a289755 | 2007-09-28 14:01:25 +0200 | [diff] [blame] | 273 | case IEEE80211_IF_TYPE_INVALID: |
| 274 | /* cannot happen */ |
| 275 | WARN_ON(1); |
| 276 | break; |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 277 | } |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 278 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 279 | if (local->open_count == 0) { |
| 280 | res = 0; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 281 | if (local->ops->start) |
| 282 | res = local->ops->start(local_to_hw(local)); |
| 283 | if (res) |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 284 | return res; |
Michael Buesch | ceffefd | 2008-02-10 14:16:52 +0100 | [diff] [blame] | 285 | need_hw_reconfig = 1; |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 286 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 287 | } |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 288 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 289 | switch (sdata->vif.type) { |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 290 | case IEEE80211_IF_TYPE_VLAN: |
| 291 | list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans); |
| 292 | /* no need to tell driver */ |
| 293 | break; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 294 | case IEEE80211_IF_TYPE_MNTR: |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 295 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
| 296 | local->cooked_mntrs++; |
| 297 | break; |
| 298 | } |
| 299 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 300 | /* must be before the call to ieee80211_configure_filter */ |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 301 | local->monitors++; |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 302 | if (local->monitors == 1) |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 303 | local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 304 | |
| 305 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) |
| 306 | local->fif_fcsfail++; |
| 307 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) |
| 308 | local->fif_plcpfail++; |
| 309 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) |
| 310 | local->fif_control++; |
| 311 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) |
| 312 | local->fif_other_bss++; |
| 313 | |
| 314 | netif_tx_lock_bh(local->mdev); |
| 315 | ieee80211_configure_filter(local); |
| 316 | netif_tx_unlock_bh(local->mdev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 317 | break; |
| 318 | case IEEE80211_IF_TYPE_STA: |
| 319 | case IEEE80211_IF_TYPE_IBSS: |
| 320 | sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
| 321 | /* fall through */ |
| 322 | default: |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 323 | conf.vif = &sdata->vif; |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 324 | conf.type = sdata->vif.type; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 325 | conf.mac_addr = dev->dev_addr; |
| 326 | res = local->ops->add_interface(local_to_hw(local), &conf); |
| 327 | if (res && !local->open_count && local->ops->stop) |
| 328 | local->ops->stop(local_to_hw(local)); |
| 329 | if (res) |
| 330 | return res; |
| 331 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 332 | ieee80211_if_config(dev); |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 333 | ieee80211_reset_erp_info(dev); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 334 | ieee80211_enable_keys(sdata); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 335 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 336 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA && |
Johannes Berg | ddd3d2b | 2007-09-26 17:53:20 +0200 | [diff] [blame] | 337 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 338 | netif_carrier_off(dev); |
| 339 | else |
| 340 | netif_carrier_on(dev); |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 341 | } |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 342 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 343 | if (local->open_count == 0) { |
| 344 | res = dev_open(local->mdev); |
| 345 | WARN_ON(res); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 346 | tasklet_enable(&local->tx_pending_tasklet); |
| 347 | tasklet_enable(&local->tasklet); |
| 348 | } |
| 349 | |
Johannes Berg | c1428b3 | 2007-11-16 02:54:53 +0100 | [diff] [blame] | 350 | /* |
| 351 | * set_multicast_list will be invoked by the networking core |
| 352 | * which will check whether any increments here were done in |
| 353 | * error and sync them down to the hardware as filter flags. |
| 354 | */ |
| 355 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) |
| 356 | atomic_inc(&local->iff_allmultis); |
| 357 | |
| 358 | if (sdata->flags & IEEE80211_SDATA_PROMISC) |
| 359 | atomic_inc(&local->iff_promiscs); |
| 360 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 361 | local->open_count++; |
Michael Buesch | ceffefd | 2008-02-10 14:16:52 +0100 | [diff] [blame] | 362 | if (need_hw_reconfig) |
| 363 | ieee80211_hw_config(local); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 364 | |
| 365 | netif_start_queue(dev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 366 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 370 | static int ieee80211_stop(struct net_device *dev) |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 371 | { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 372 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 373 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 374 | struct ieee80211_if_init_conf conf; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 375 | struct sta_info *sta; |
| 376 | int i; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 377 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 378 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 379 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 380 | list_for_each_entry(sta, &local->sta_list, list) { |
Ron Rindjunsky | 5b3d71d | 2008-01-13 18:21:58 +0200 | [diff] [blame] | 381 | if (sta->dev == dev) |
| 382 | for (i = 0; i < STA_TID_NUM; i++) |
| 383 | ieee80211_sta_stop_rx_ba_session(sta->dev, |
| 384 | sta->addr, i, |
| 385 | WLAN_BACK_RECIPIENT, |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 386 | WLAN_REASON_QSTA_LEAVE_QBSS); |
| 387 | } |
| 388 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 389 | netif_stop_queue(dev); |
| 390 | |
Johannes Berg | c1428b3 | 2007-11-16 02:54:53 +0100 | [diff] [blame] | 391 | /* |
| 392 | * Don't count this interface for promisc/allmulti while it |
| 393 | * is down. dev_mc_unsync() will invoke set_multicast_list |
| 394 | * on the master interface which will sync these down to the |
| 395 | * hardware as filter flags. |
| 396 | */ |
| 397 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) |
| 398 | atomic_dec(&local->iff_allmultis); |
| 399 | |
| 400 | if (sdata->flags & IEEE80211_SDATA_PROMISC) |
| 401 | atomic_dec(&local->iff_promiscs); |
| 402 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 403 | dev_mc_unsync(local->mdev, dev); |
| 404 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 405 | /* APs need special treatment */ |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 406 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 407 | struct ieee80211_sub_if_data *vlan, *tmp; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 408 | struct beacon_data *old_beacon = sdata->u.ap.beacon; |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 409 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 410 | /* remove beacon */ |
| 411 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 412 | synchronize_rcu(); |
| 413 | kfree(old_beacon); |
| 414 | |
| 415 | /* down all dependent devices, that is VLANs */ |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 416 | list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans, |
| 417 | u.vlan.list) |
| 418 | dev_close(vlan->dev); |
| 419 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); |
| 420 | } |
| 421 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 422 | local->open_count--; |
| 423 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 424 | switch (sdata->vif.type) { |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 425 | case IEEE80211_IF_TYPE_VLAN: |
| 426 | list_del(&sdata->u.vlan.list); |
| 427 | sdata->u.vlan.ap = NULL; |
| 428 | /* no need to tell driver */ |
| 429 | break; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 430 | case IEEE80211_IF_TYPE_MNTR: |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 431 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
| 432 | local->cooked_mntrs--; |
| 433 | break; |
| 434 | } |
| 435 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 436 | local->monitors--; |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 437 | if (local->monitors == 0) |
Michael Wu | 8b393f1 | 2007-11-28 01:57:08 -0500 | [diff] [blame] | 438 | local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 439 | |
| 440 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) |
| 441 | local->fif_fcsfail--; |
| 442 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) |
| 443 | local->fif_plcpfail--; |
| 444 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) |
| 445 | local->fif_control--; |
| 446 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) |
| 447 | local->fif_other_bss--; |
| 448 | |
| 449 | netif_tx_lock_bh(local->mdev); |
| 450 | ieee80211_configure_filter(local); |
| 451 | netif_tx_unlock_bh(local->mdev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 452 | break; |
Luis Carlos Cobo | f7a9214 | 2008-02-23 15:17:18 +0100 | [diff] [blame^] | 453 | case IEEE80211_IF_TYPE_MESH_POINT: |
| 454 | sta_info_flush(local, dev); |
| 455 | /* fall through */ |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 456 | case IEEE80211_IF_TYPE_STA: |
| 457 | case IEEE80211_IF_TYPE_IBSS: |
| 458 | sdata->u.sta.state = IEEE80211_DISABLED; |
| 459 | del_timer_sync(&sdata->u.sta.timer); |
Johannes Berg | 2a8a9a8 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 460 | /* |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 461 | * When we get here, the interface is marked down. |
| 462 | * Call synchronize_rcu() to wait for the RX path |
| 463 | * should it be using the interface and enqueuing |
| 464 | * frames at this very time on another CPU. |
Johannes Berg | 2a8a9a8 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 465 | */ |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 466 | synchronize_rcu(); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 467 | skb_queue_purge(&sdata->u.sta.skb_queue); |
Johannes Berg | 2a8a9a8 | 2007-08-28 17:01:52 -0400 | [diff] [blame] | 468 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 469 | if (local->scan_dev == sdata->dev) { |
| 470 | if (!local->ops->hw_scan) { |
| 471 | local->sta_sw_scanning = 0; |
| 472 | cancel_delayed_work(&local->scan_work); |
| 473 | } else |
| 474 | local->sta_hw_scanning = 0; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 475 | } |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 476 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 477 | flush_workqueue(local->hw.workqueue); |
Zhu Yi | a10605e | 2007-11-22 11:10:22 +0800 | [diff] [blame] | 478 | |
| 479 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; |
| 480 | kfree(sdata->u.sta.extra_ie); |
| 481 | sdata->u.sta.extra_ie = NULL; |
| 482 | sdata->u.sta.extra_ie_len = 0; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 483 | /* fall through */ |
| 484 | default: |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 485 | conf.vif = &sdata->vif; |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 486 | conf.type = sdata->vif.type; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 487 | conf.mac_addr = dev->dev_addr; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 488 | /* disable all keys for as long as this netdev is down */ |
| 489 | ieee80211_disable_keys(sdata); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 490 | local->ops->remove_interface(local_to_hw(local), &conf); |
| 491 | } |
| 492 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 493 | if (local->open_count == 0) { |
| 494 | if (netif_running(local->mdev)) |
| 495 | dev_close(local->mdev); |
| 496 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 497 | if (local->ops->stop) |
| 498 | local->ops->stop(local_to_hw(local)); |
| 499 | |
Ivo van Doorn | cdcb006 | 2008-01-07 19:45:24 +0100 | [diff] [blame] | 500 | ieee80211_led_radio(local, 0); |
| 501 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 502 | tasklet_disable(&local->tx_pending_tasklet); |
| 503 | tasklet_disable(&local->tasklet); |
| 504 | } |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 509 | int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid) |
| 510 | { |
| 511 | struct ieee80211_local *local = hw_to_local(hw); |
| 512 | struct sta_info *sta; |
| 513 | struct ieee80211_sub_if_data *sdata; |
| 514 | u16 start_seq_num = 0; |
| 515 | u8 *state; |
| 516 | int ret; |
| 517 | DECLARE_MAC_BUF(mac); |
| 518 | |
| 519 | if (tid >= STA_TID_NUM) |
| 520 | return -EINVAL; |
| 521 | |
| 522 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 523 | printk(KERN_DEBUG "Open BA session requested for %s tid %u\n", |
| 524 | print_mac(mac, ra), tid); |
| 525 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 526 | |
| 527 | sta = sta_info_get(local, ra); |
| 528 | if (!sta) { |
| 529 | printk(KERN_DEBUG "Could not find the station\n"); |
| 530 | return -ENOENT; |
| 531 | } |
| 532 | |
| 533 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 534 | |
| 535 | /* we have tried too many times, receiver does not want A-MPDU */ |
| 536 | if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) { |
| 537 | ret = -EBUSY; |
| 538 | goto start_ba_exit; |
| 539 | } |
| 540 | |
| 541 | state = &sta->ampdu_mlme.tid_tx[tid].state; |
| 542 | /* check if the TID is not in aggregation flow already */ |
| 543 | if (*state != HT_AGG_STATE_IDLE) { |
| 544 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 545 | printk(KERN_DEBUG "BA request denied - session is not " |
| 546 | "idle on tid %u\n", tid); |
| 547 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 548 | ret = -EAGAIN; |
| 549 | goto start_ba_exit; |
| 550 | } |
| 551 | |
| 552 | /* ensure that TX flow won't interrupt us |
| 553 | * until the end of the call to requeue function */ |
| 554 | spin_lock_bh(&local->mdev->queue_lock); |
| 555 | |
| 556 | /* create a new queue for this aggregation */ |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 557 | ret = ieee80211_ht_agg_queue_add(local, sta, tid); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 558 | |
| 559 | /* case no queue is available to aggregation |
| 560 | * don't switch to aggregation */ |
| 561 | if (ret) { |
| 562 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 563 | printk(KERN_DEBUG "BA request denied - no queue available for" |
| 564 | " tid %d\n", tid); |
| 565 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 566 | spin_unlock_bh(&local->mdev->queue_lock); |
| 567 | goto start_ba_exit; |
| 568 | } |
| 569 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); |
| 570 | |
| 571 | /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the |
| 572 | * call back right away, it must see that the flow has begun */ |
| 573 | *state |= HT_ADDBA_REQUESTED_MSK; |
| 574 | |
| 575 | if (local->ops->ampdu_action) |
| 576 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, |
| 577 | ra, tid, &start_seq_num); |
| 578 | |
| 579 | if (ret) { |
| 580 | /* No need to requeue the packets in the agg queue, since we |
| 581 | * held the tx lock: no packet could be enqueued to the newly |
| 582 | * allocated queue */ |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 583 | ieee80211_ht_agg_queue_remove(local, sta, tid, 0); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 584 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 585 | printk(KERN_DEBUG "BA request denied - HW or queue unavailable" |
| 586 | " for tid %d\n", tid); |
| 587 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 588 | spin_unlock_bh(&local->mdev->queue_lock); |
| 589 | *state = HT_AGG_STATE_IDLE; |
| 590 | goto start_ba_exit; |
| 591 | } |
| 592 | |
| 593 | /* Will put all the packets in the new SW queue */ |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 594 | ieee80211_requeue(local, ieee802_1d_to_ac[tid]); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 595 | spin_unlock_bh(&local->mdev->queue_lock); |
| 596 | |
| 597 | /* We have most probably almost emptied the legacy queue */ |
| 598 | /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */ |
| 599 | |
| 600 | /* send an addBA request */ |
| 601 | sta->ampdu_mlme.dialog_token_allocator++; |
| 602 | sta->ampdu_mlme.tid_tx[tid].dialog_token = |
| 603 | sta->ampdu_mlme.dialog_token_allocator; |
| 604 | sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num; |
| 605 | |
| 606 | ieee80211_send_addba_request(sta->dev, ra, tid, |
| 607 | sta->ampdu_mlme.tid_tx[tid].dialog_token, |
| 608 | sta->ampdu_mlme.tid_tx[tid].ssn, |
| 609 | 0x40, 5000); |
| 610 | |
| 611 | /* activate the timer for the recipient's addBA response */ |
| 612 | sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires = |
| 613 | jiffies + ADDBA_RESP_INTERVAL; |
| 614 | add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer); |
| 615 | printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid); |
| 616 | |
| 617 | start_ba_exit: |
| 618 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 619 | sta_info_put(sta); |
| 620 | return ret; |
| 621 | } |
| 622 | EXPORT_SYMBOL(ieee80211_start_tx_ba_session); |
| 623 | |
| 624 | int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw, |
| 625 | u8 *ra, u16 tid, |
| 626 | enum ieee80211_back_parties initiator) |
| 627 | { |
| 628 | struct ieee80211_local *local = hw_to_local(hw); |
| 629 | struct sta_info *sta; |
| 630 | u8 *state; |
| 631 | int ret = 0; |
| 632 | DECLARE_MAC_BUF(mac); |
| 633 | |
| 634 | if (tid >= STA_TID_NUM) |
| 635 | return -EINVAL; |
| 636 | |
| 637 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 638 | printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n", |
| 639 | print_mac(mac, ra), tid); |
| 640 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 641 | |
| 642 | sta = sta_info_get(local, ra); |
| 643 | if (!sta) |
| 644 | return -ENOENT; |
| 645 | |
| 646 | /* check if the TID is in aggregation */ |
| 647 | state = &sta->ampdu_mlme.tid_tx[tid].state; |
| 648 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 649 | |
| 650 | if (*state != HT_AGG_STATE_OPERATIONAL) { |
| 651 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 652 | printk(KERN_DEBUG "Try to stop Tx aggregation on" |
| 653 | " non active TID\n"); |
| 654 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 655 | ret = -ENOENT; |
| 656 | goto stop_BA_exit; |
| 657 | } |
| 658 | |
| 659 | ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]); |
| 660 | |
| 661 | *state = HT_AGG_STATE_REQ_STOP_BA_MSK | |
| 662 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); |
| 663 | |
| 664 | if (local->ops->ampdu_action) |
| 665 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP, |
| 666 | ra, tid, NULL); |
| 667 | |
| 668 | /* case HW denied going back to legacy */ |
| 669 | if (ret) { |
| 670 | WARN_ON(ret != -EBUSY); |
| 671 | *state = HT_AGG_STATE_OPERATIONAL; |
| 672 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); |
| 673 | goto stop_BA_exit; |
| 674 | } |
| 675 | |
| 676 | stop_BA_exit: |
| 677 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 678 | sta_info_put(sta); |
| 679 | return ret; |
| 680 | } |
| 681 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_session); |
| 682 | |
| 683 | void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) |
| 684 | { |
| 685 | struct ieee80211_local *local = hw_to_local(hw); |
| 686 | struct sta_info *sta; |
| 687 | u8 *state; |
| 688 | DECLARE_MAC_BUF(mac); |
| 689 | |
| 690 | if (tid >= STA_TID_NUM) { |
| 691 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", |
| 692 | tid, STA_TID_NUM); |
| 693 | return; |
| 694 | } |
| 695 | |
| 696 | sta = sta_info_get(local, ra); |
| 697 | if (!sta) { |
| 698 | printk(KERN_DEBUG "Could not find station: %s\n", |
| 699 | print_mac(mac, ra)); |
| 700 | return; |
| 701 | } |
| 702 | |
| 703 | state = &sta->ampdu_mlme.tid_tx[tid].state; |
| 704 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 705 | |
| 706 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
| 707 | printk(KERN_DEBUG "addBA was not requested yet, state is %d\n", |
| 708 | *state); |
| 709 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 710 | sta_info_put(sta); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK); |
| 715 | |
| 716 | *state |= HT_ADDBA_DRV_READY_MSK; |
| 717 | |
| 718 | if (*state == HT_AGG_STATE_OPERATIONAL) { |
| 719 | printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid); |
| 720 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); |
| 721 | } |
| 722 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 723 | sta_info_put(sta); |
| 724 | } |
| 725 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb); |
| 726 | |
| 727 | void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid) |
| 728 | { |
| 729 | struct ieee80211_local *local = hw_to_local(hw); |
| 730 | struct sta_info *sta; |
| 731 | u8 *state; |
| 732 | int agg_queue; |
| 733 | DECLARE_MAC_BUF(mac); |
| 734 | |
| 735 | if (tid >= STA_TID_NUM) { |
| 736 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", |
| 737 | tid, STA_TID_NUM); |
| 738 | return; |
| 739 | } |
| 740 | |
| 741 | printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n", |
| 742 | print_mac(mac, ra), tid); |
| 743 | |
| 744 | sta = sta_info_get(local, ra); |
| 745 | if (!sta) { |
| 746 | printk(KERN_DEBUG "Could not find station: %s\n", |
| 747 | print_mac(mac, ra)); |
| 748 | return; |
| 749 | } |
| 750 | state = &sta->ampdu_mlme.tid_tx[tid].state; |
| 751 | |
| 752 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 753 | if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) { |
| 754 | printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n"); |
| 755 | sta_info_put(sta); |
| 756 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | if (*state & HT_AGG_STATE_INITIATOR_MSK) |
| 761 | ieee80211_send_delba(sta->dev, ra, tid, |
| 762 | WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE); |
| 763 | |
| 764 | agg_queue = sta->tid_to_tx_q[tid]; |
| 765 | |
| 766 | /* avoid ordering issues: we are the only one that can modify |
| 767 | * the content of the qdiscs */ |
| 768 | spin_lock_bh(&local->mdev->queue_lock); |
| 769 | /* remove the queue for this aggregation */ |
Ron Rindjunsky | 9e72349 | 2008-01-28 14:07:18 +0200 | [diff] [blame] | 770 | ieee80211_ht_agg_queue_remove(local, sta, tid, 1); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 771 | spin_unlock_bh(&local->mdev->queue_lock); |
| 772 | |
| 773 | /* we just requeued the all the frames that were in the removed |
| 774 | * queue, and since we might miss a softirq we do netif_schedule. |
| 775 | * ieee80211_wake_queue is not used here as this queue is not |
| 776 | * necessarily stopped */ |
| 777 | netif_schedule(local->mdev); |
| 778 | *state = HT_AGG_STATE_IDLE; |
| 779 | sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0; |
| 780 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); |
| 781 | |
| 782 | sta_info_put(sta); |
| 783 | } |
| 784 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb); |
| 785 | |
| 786 | void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, |
| 787 | const u8 *ra, u16 tid) |
| 788 | { |
| 789 | struct ieee80211_local *local = hw_to_local(hw); |
| 790 | struct ieee80211_ra_tid *ra_tid; |
| 791 | struct sk_buff *skb = dev_alloc_skb(0); |
| 792 | |
| 793 | if (unlikely(!skb)) { |
| 794 | if (net_ratelimit()) |
| 795 | printk(KERN_WARNING "%s: Not enough memory, " |
| 796 | "dropping start BA session", skb->dev->name); |
| 797 | return; |
| 798 | } |
| 799 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; |
| 800 | memcpy(&ra_tid->ra, ra, ETH_ALEN); |
| 801 | ra_tid->tid = tid; |
| 802 | |
| 803 | skb->pkt_type = IEEE80211_ADDBA_MSG; |
| 804 | skb_queue_tail(&local->skb_queue, skb); |
| 805 | tasklet_schedule(&local->tasklet); |
| 806 | } |
| 807 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe); |
| 808 | |
| 809 | void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, |
| 810 | const u8 *ra, u16 tid) |
| 811 | { |
| 812 | struct ieee80211_local *local = hw_to_local(hw); |
| 813 | struct ieee80211_ra_tid *ra_tid; |
| 814 | struct sk_buff *skb = dev_alloc_skb(0); |
| 815 | |
| 816 | if (unlikely(!skb)) { |
| 817 | if (net_ratelimit()) |
| 818 | printk(KERN_WARNING "%s: Not enough memory, " |
| 819 | "dropping stop BA session", skb->dev->name); |
| 820 | return; |
| 821 | } |
| 822 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; |
| 823 | memcpy(&ra_tid->ra, ra, ETH_ALEN); |
| 824 | ra_tid->tid = tid; |
| 825 | |
| 826 | skb->pkt_type = IEEE80211_DELBA_MSG; |
| 827 | skb_queue_tail(&local->skb_queue, skb); |
| 828 | tasklet_schedule(&local->tasklet); |
| 829 | } |
| 830 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe); |
| 831 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 832 | static void ieee80211_set_multicast_list(struct net_device *dev) |
| 833 | { |
| 834 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 835 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 836 | int allmulti, promisc, sdata_allmulti, sdata_promisc; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 837 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 838 | allmulti = !!(dev->flags & IFF_ALLMULTI); |
| 839 | promisc = !!(dev->flags & IFF_PROMISC); |
Johannes Berg | b52f219 | 2007-11-16 01:49:11 +0100 | [diff] [blame] | 840 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); |
| 841 | sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 842 | |
| 843 | if (allmulti != sdata_allmulti) { |
| 844 | if (dev->flags & IFF_ALLMULTI) |
Johannes Berg | 5391899 | 2007-09-26 15:19:47 +0200 | [diff] [blame] | 845 | atomic_inc(&local->iff_allmultis); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 846 | else |
Johannes Berg | 5391899 | 2007-09-26 15:19:47 +0200 | [diff] [blame] | 847 | atomic_dec(&local->iff_allmultis); |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 848 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 849 | } |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 850 | |
| 851 | if (promisc != sdata_promisc) { |
| 852 | if (dev->flags & IFF_PROMISC) |
Johannes Berg | 5391899 | 2007-09-26 15:19:47 +0200 | [diff] [blame] | 853 | atomic_inc(&local->iff_promiscs); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 854 | else |
Johannes Berg | 5391899 | 2007-09-26 15:19:47 +0200 | [diff] [blame] | 855 | atomic_dec(&local->iff_promiscs); |
Jiri Slaby | 13262ff | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 856 | sdata->flags ^= IEEE80211_SDATA_PROMISC; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 857 | } |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 858 | |
| 859 | dev_mc_sync(local->mdev, dev); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 860 | } |
| 861 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 862 | static const struct header_ops ieee80211_header_ops = { |
| 863 | .create = eth_header, |
| 864 | .parse = header_parse_80211, |
| 865 | .rebuild = eth_rebuild_header, |
| 866 | .cache = eth_header_cache, |
| 867 | .cache_update = eth_header_cache_update, |
| 868 | }; |
| 869 | |
Johannes Berg | f9d540e | 2007-09-28 14:02:09 +0200 | [diff] [blame] | 870 | /* Must not be called for mdev */ |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 871 | void ieee80211_if_setup(struct net_device *dev) |
| 872 | { |
| 873 | ether_setup(dev); |
| 874 | dev->hard_start_xmit = ieee80211_subif_start_xmit; |
| 875 | dev->wireless_handlers = &ieee80211_iw_handler_def; |
| 876 | dev->set_multicast_list = ieee80211_set_multicast_list; |
| 877 | dev->change_mtu = ieee80211_change_mtu; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 878 | dev->open = ieee80211_open; |
| 879 | dev->stop = ieee80211_stop; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 880 | dev->destructor = ieee80211_if_free; |
| 881 | } |
| 882 | |
| 883 | /* WDS specialties */ |
| 884 | |
| 885 | int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr) |
| 886 | { |
| 887 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 888 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 889 | struct sta_info *sta; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 890 | DECLARE_MAC_BUF(mac); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 891 | |
| 892 | if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0) |
| 893 | return 0; |
| 894 | |
| 895 | /* Create STA entry for the new peer */ |
| 896 | sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL); |
Johannes Berg | 43ba7e9 | 2008-02-21 14:09:30 +0100 | [diff] [blame] | 897 | if (IS_ERR(sta)) |
| 898 | return PTR_ERR(sta); |
Johannes Berg | 238814f | 2008-01-28 17:19:37 +0100 | [diff] [blame] | 899 | |
| 900 | sta->flags |= WLAN_STA_AUTHORIZED; |
| 901 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 902 | sta_info_put(sta); |
| 903 | |
| 904 | /* Remove STA entry for the old peer */ |
| 905 | sta = sta_info_get(local, sdata->u.wds.remote_addr); |
| 906 | if (sta) { |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 907 | sta_info_free(sta); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 908 | sta_info_put(sta); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 909 | } else { |
| 910 | printk(KERN_DEBUG "%s: could not find STA entry for WDS link " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 911 | "peer %s\n", |
| 912 | dev->name, print_mac(mac, sdata->u.wds.remote_addr)); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /* Update WDS link data */ |
| 916 | memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN); |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | /* everything else */ |
| 922 | |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 923 | static int __ieee80211_if_config(struct net_device *dev, |
| 924 | struct sk_buff *beacon, |
| 925 | struct ieee80211_tx_control *control) |
| 926 | { |
| 927 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 928 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 929 | struct ieee80211_if_conf conf; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 930 | |
| 931 | if (!local->ops->config_interface || !netif_running(dev)) |
| 932 | return 0; |
| 933 | |
| 934 | memset(&conf, 0, sizeof(conf)); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 935 | conf.type = sdata->vif.type; |
| 936 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
| 937 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 938 | conf.bssid = sdata->u.sta.bssid; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 939 | conf.ssid = sdata->u.sta.ssid; |
| 940 | conf.ssid_len = sdata->u.sta.ssid_len; |
Luis Carlos Cobo | f7a9214 | 2008-02-23 15:17:18 +0100 | [diff] [blame^] | 941 | #ifdef CONFIG_MAC80211_MESH |
| 942 | } else if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) { |
| 943 | conf.beacon = beacon; |
| 944 | ieee80211_start_mesh(dev); |
| 945 | #endif |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 946 | } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 947 | conf.ssid = sdata->u.ap.ssid; |
| 948 | conf.ssid_len = sdata->u.ap.ssid_len; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 949 | conf.beacon = beacon; |
| 950 | conf.beacon_control = control; |
| 951 | } |
| 952 | return local->ops->config_interface(local_to_hw(local), |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 953 | &sdata->vif, &conf); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | int ieee80211_if_config(struct net_device *dev) |
| 957 | { |
Luis Carlos Cobo | f7a9214 | 2008-02-23 15:17:18 +0100 | [diff] [blame^] | 958 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 959 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 960 | if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT && |
| 961 | (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE)) |
| 962 | return ieee80211_if_config_beacon(dev); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 963 | return __ieee80211_if_config(dev, NULL, NULL); |
| 964 | } |
| 965 | |
| 966 | int ieee80211_if_config_beacon(struct net_device *dev) |
| 967 | { |
| 968 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 969 | struct ieee80211_tx_control control; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 970 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 971 | struct sk_buff *skb; |
| 972 | |
| 973 | if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE)) |
| 974 | return 0; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 975 | skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif, |
| 976 | &control); |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 977 | if (!skb) |
| 978 | return -ENOMEM; |
| 979 | return __ieee80211_if_config(dev, skb, &control); |
| 980 | } |
| 981 | |
| 982 | int ieee80211_hw_config(struct ieee80211_local *local) |
| 983 | { |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 984 | struct ieee80211_channel *chan; |
| 985 | int ret = 0; |
| 986 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 987 | if (local->sta_sw_scanning) |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 988 | chan = local->scan_channel; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 989 | else |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 990 | chan = local->oper_channel; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 991 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 992 | local->hw.conf.channel = chan; |
| 993 | |
| 994 | if (!local->hw.conf.power_level) |
| 995 | local->hw.conf.power_level = chan->max_power; |
| 996 | else |
| 997 | local->hw.conf.power_level = min(chan->max_power, |
| 998 | local->hw.conf.power_level); |
| 999 | |
| 1000 | local->hw.conf.max_antenna_gain = chan->max_antenna_gain; |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1001 | |
| 1002 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1003 | printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n", |
| 1004 | wiphy_name(local->hw.wiphy), chan->center_freq); |
| 1005 | #endif |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1006 | |
Michael Buesch | f7c4dae | 2007-09-24 18:41:49 +0200 | [diff] [blame] | 1007 | if (local->open_count) |
Johannes Berg | b2c258f | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1008 | ret = local->ops->config(local_to_hw(local), &local->hw.conf); |
| 1009 | |
| 1010 | return ret; |
| 1011 | } |
| 1012 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1013 | /** |
| 1014 | * ieee80211_hw_config_ht should be used only after legacy configuration |
| 1015 | * has been determined, as ht configuration depends upon the hardware's |
| 1016 | * HT abilities for a _specific_ band. |
| 1017 | */ |
| 1018 | int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht, |
| 1019 | struct ieee80211_ht_info *req_ht_cap, |
| 1020 | struct ieee80211_ht_bss_info *req_bss_cap) |
| 1021 | { |
| 1022 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1023 | struct ieee80211_supported_band *sband; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1024 | int i; |
| 1025 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1026 | sband = local->hw.wiphy->bands[conf->channel->band]; |
| 1027 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1028 | /* HT is not supported */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1029 | if (!sband->ht_info.ht_supported) { |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1030 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; |
| 1031 | return -EOPNOTSUPP; |
| 1032 | } |
| 1033 | |
| 1034 | /* disable HT */ |
| 1035 | if (!enable_ht) { |
| 1036 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; |
| 1037 | } else { |
| 1038 | conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1039 | conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1040 | conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS); |
| 1041 | conf->ht_conf.cap |= |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1042 | sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1043 | conf->ht_bss_conf.primary_channel = |
| 1044 | req_bss_cap->primary_channel; |
| 1045 | conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap; |
| 1046 | conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode; |
| 1047 | for (i = 0; i < SUPP_MCS_SET_LEN; i++) |
| 1048 | conf->ht_conf.supp_mcs_set[i] = |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1049 | sband->ht_info.supp_mcs_set[i] & |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1050 | req_ht_cap->supp_mcs_set[i]; |
| 1051 | |
| 1052 | /* In STA mode, this gives us indication |
| 1053 | * to the AP's mode of operation */ |
| 1054 | conf->ht_conf.ht_supported = 1; |
| 1055 | conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor; |
| 1056 | conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density; |
| 1057 | } |
| 1058 | |
| 1059 | local->ops->conf_ht(local_to_hw(local), &local->hw.conf); |
| 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1064 | void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, |
| 1065 | u32 changed) |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1066 | { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1067 | struct ieee80211_local *local = sdata->local; |
| 1068 | |
| 1069 | if (!changed) |
| 1070 | return; |
| 1071 | |
| 1072 | if (local->ops->bss_info_changed) |
| 1073 | local->ops->bss_info_changed(local_to_hw(local), |
| 1074 | &sdata->vif, |
| 1075 | &sdata->bss_conf, |
| 1076 | changed); |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | void ieee80211_reset_erp_info(struct net_device *dev) |
| 1080 | { |
| 1081 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1082 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1083 | sdata->bss_conf.use_cts_prot = 0; |
| 1084 | sdata->bss_conf.use_short_preamble = 0; |
| 1085 | ieee80211_bss_info_change_notify(sdata, |
| 1086 | BSS_CHANGED_ERP_CTS_PROT | |
| 1087 | BSS_CHANGED_ERP_PREAMBLE); |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1088 | } |
| 1089 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1090 | void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw, |
| 1091 | struct sk_buff *skb, |
| 1092 | struct ieee80211_tx_status *status) |
| 1093 | { |
| 1094 | struct ieee80211_local *local = hw_to_local(hw); |
| 1095 | struct ieee80211_tx_status *saved; |
| 1096 | int tmp; |
| 1097 | |
| 1098 | skb->dev = local->mdev; |
| 1099 | saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC); |
| 1100 | if (unlikely(!saved)) { |
| 1101 | if (net_ratelimit()) |
| 1102 | printk(KERN_WARNING "%s: Not enough memory, " |
| 1103 | "dropping tx status", skb->dev->name); |
| 1104 | /* should be dev_kfree_skb_irq, but due to this function being |
| 1105 | * named _irqsafe instead of just _irq we can't be sure that |
| 1106 | * people won't call it from non-irq contexts */ |
| 1107 | dev_kfree_skb_any(skb); |
| 1108 | return; |
| 1109 | } |
| 1110 | memcpy(saved, status, sizeof(struct ieee80211_tx_status)); |
| 1111 | /* copy pointer to saved status into skb->cb for use by tasklet */ |
| 1112 | memcpy(skb->cb, &saved, sizeof(saved)); |
| 1113 | |
| 1114 | skb->pkt_type = IEEE80211_TX_STATUS_MSG; |
| 1115 | skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ? |
| 1116 | &local->skb_queue : &local->skb_queue_unreliable, skb); |
| 1117 | tmp = skb_queue_len(&local->skb_queue) + |
| 1118 | skb_queue_len(&local->skb_queue_unreliable); |
| 1119 | while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT && |
| 1120 | (skb = skb_dequeue(&local->skb_queue_unreliable))) { |
| 1121 | memcpy(&saved, skb->cb, sizeof(saved)); |
| 1122 | kfree(saved); |
| 1123 | dev_kfree_skb_irq(skb); |
| 1124 | tmp--; |
| 1125 | I802_DEBUG_INC(local->tx_status_drop); |
| 1126 | } |
| 1127 | tasklet_schedule(&local->tasklet); |
| 1128 | } |
| 1129 | EXPORT_SYMBOL(ieee80211_tx_status_irqsafe); |
| 1130 | |
| 1131 | static void ieee80211_tasklet_handler(unsigned long data) |
| 1132 | { |
| 1133 | struct ieee80211_local *local = (struct ieee80211_local *) data; |
| 1134 | struct sk_buff *skb; |
| 1135 | struct ieee80211_rx_status rx_status; |
| 1136 | struct ieee80211_tx_status *tx_status; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1137 | struct ieee80211_ra_tid *ra_tid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1138 | |
| 1139 | while ((skb = skb_dequeue(&local->skb_queue)) || |
| 1140 | (skb = skb_dequeue(&local->skb_queue_unreliable))) { |
| 1141 | switch (skb->pkt_type) { |
| 1142 | case IEEE80211_RX_MSG: |
| 1143 | /* status is in skb->cb */ |
| 1144 | memcpy(&rx_status, skb->cb, sizeof(rx_status)); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1145 | /* Clear skb->pkt_type in order to not confuse kernel |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1146 | * netstack. */ |
| 1147 | skb->pkt_type = 0; |
| 1148 | __ieee80211_rx(local_to_hw(local), skb, &rx_status); |
| 1149 | break; |
| 1150 | case IEEE80211_TX_STATUS_MSG: |
| 1151 | /* get pointer to saved status out of skb->cb */ |
| 1152 | memcpy(&tx_status, skb->cb, sizeof(tx_status)); |
| 1153 | skb->pkt_type = 0; |
| 1154 | ieee80211_tx_status(local_to_hw(local), |
| 1155 | skb, tx_status); |
| 1156 | kfree(tx_status); |
| 1157 | break; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1158 | case IEEE80211_DELBA_MSG: |
| 1159 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; |
| 1160 | ieee80211_stop_tx_ba_cb(local_to_hw(local), |
| 1161 | ra_tid->ra, ra_tid->tid); |
| 1162 | dev_kfree_skb(skb); |
| 1163 | break; |
| 1164 | case IEEE80211_ADDBA_MSG: |
| 1165 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; |
| 1166 | ieee80211_start_tx_ba_cb(local_to_hw(local), |
| 1167 | ra_tid->ra, ra_tid->tid); |
| 1168 | dev_kfree_skb(skb); |
| 1169 | break ; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1170 | default: /* should never get here! */ |
| 1171 | printk(KERN_ERR "%s: Unknown message type (%d)\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 1172 | wiphy_name(local->hw.wiphy), skb->pkt_type); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1173 | dev_kfree_skb(skb); |
| 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1179 | /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to |
| 1180 | * make a prepared TX frame (one that has been given to hw) to look like brand |
| 1181 | * new IEEE 802.11 frame that is ready to go through TX processing again. |
| 1182 | * Also, tx_packet_data in cb is restored from tx_control. */ |
| 1183 | static void ieee80211_remove_tx_extra(struct ieee80211_local *local, |
| 1184 | struct ieee80211_key *key, |
| 1185 | struct sk_buff *skb, |
| 1186 | struct ieee80211_tx_control *control) |
| 1187 | { |
| 1188 | int hdrlen, iv_len, mic_len; |
| 1189 | struct ieee80211_tx_packet_data *pkt_data; |
| 1190 | |
| 1191 | pkt_data = (struct ieee80211_tx_packet_data *)skb->cb; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 1192 | pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex; |
Jiri Slaby | e8bf964 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1193 | pkt_data->flags = 0; |
| 1194 | if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS) |
| 1195 | pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS; |
| 1196 | if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT) |
| 1197 | pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT; |
| 1198 | if (control->flags & IEEE80211_TXCTL_REQUEUE) |
| 1199 | pkt_data->flags |= IEEE80211_TXPD_REQUEUE; |
Johannes Berg | 678f5f71 | 2007-12-19 01:31:23 +0100 | [diff] [blame] | 1200 | if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME) |
| 1201 | pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1202 | pkt_data->queue = control->queue; |
| 1203 | |
| 1204 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); |
| 1205 | |
| 1206 | if (!key) |
| 1207 | goto no_key; |
| 1208 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1209 | switch (key->conf.alg) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1210 | case ALG_WEP: |
| 1211 | iv_len = WEP_IV_LEN; |
| 1212 | mic_len = WEP_ICV_LEN; |
| 1213 | break; |
| 1214 | case ALG_TKIP: |
| 1215 | iv_len = TKIP_IV_LEN; |
| 1216 | mic_len = TKIP_ICV_LEN; |
| 1217 | break; |
| 1218 | case ALG_CCMP: |
| 1219 | iv_len = CCMP_HDR_LEN; |
| 1220 | mic_len = CCMP_MIC_LEN; |
| 1221 | break; |
| 1222 | default: |
| 1223 | goto no_key; |
| 1224 | } |
| 1225 | |
Johannes Berg | 8f20fc2 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1226 | if (skb->len >= mic_len && |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 1227 | !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1228 | skb_trim(skb, skb->len - mic_len); |
| 1229 | if (skb->len >= iv_len && skb->len > hdrlen) { |
| 1230 | memmove(skb->data + iv_len, skb->data, hdrlen); |
| 1231 | skb_pull(skb, iv_len); |
| 1232 | } |
| 1233 | |
| 1234 | no_key: |
| 1235 | { |
| 1236 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 1237 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 1238 | if ((fc & 0x8C) == 0x88) /* QoS Control Field */ { |
| 1239 | fc &= ~IEEE80211_STYPE_QOS_DATA; |
| 1240 | hdr->frame_control = cpu_to_le16(fc); |
| 1241 | memmove(skb->data + 2, skb->data, hdrlen - 2); |
| 1242 | skb_pull(skb, 2); |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | |
Johannes Berg | d46e144 | 2008-02-20 23:59:33 +0100 | [diff] [blame] | 1247 | static void ieee80211_handle_filtered_frame(struct ieee80211_local *local, |
| 1248 | struct sta_info *sta, |
| 1249 | struct sk_buff *skb, |
| 1250 | struct ieee80211_tx_status *status) |
| 1251 | { |
| 1252 | sta->tx_filtered_count++; |
| 1253 | |
| 1254 | /* |
| 1255 | * Clear the TX filter mask for this STA when sending the next |
| 1256 | * packet. If the STA went to power save mode, this will happen |
| 1257 | * happen when it wakes up for the next time. |
| 1258 | */ |
| 1259 | sta->flags |= WLAN_STA_CLEAR_PS_FILT; |
| 1260 | |
| 1261 | /* |
| 1262 | * This code races in the following way: |
| 1263 | * |
| 1264 | * (1) STA sends frame indicating it will go to sleep and does so |
| 1265 | * (2) hardware/firmware adds STA to filter list, passes frame up |
| 1266 | * (3) hardware/firmware processes TX fifo and suppresses a frame |
| 1267 | * (4) we get TX status before having processed the frame and |
| 1268 | * knowing that the STA has gone to sleep. |
| 1269 | * |
| 1270 | * This is actually quite unlikely even when both those events are |
| 1271 | * processed from interrupts coming in quickly after one another or |
| 1272 | * even at the same time because we queue both TX status events and |
| 1273 | * RX frames to be processed by a tasklet and process them in the |
| 1274 | * same order that they were received or TX status last. Hence, there |
| 1275 | * is no race as long as the frame RX is processed before the next TX |
| 1276 | * status, which drivers can ensure, see below. |
| 1277 | * |
| 1278 | * Note that this can only happen if the hardware or firmware can |
| 1279 | * actually add STAs to the filter list, if this is done by the |
| 1280 | * driver in response to set_tim() (which will only reduce the race |
| 1281 | * this whole filtering tries to solve, not completely solve it) |
| 1282 | * this situation cannot happen. |
| 1283 | * |
| 1284 | * To completely solve this race drivers need to make sure that they |
| 1285 | * (a) don't mix the irq-safe/not irq-safe TX status/RX processing |
| 1286 | * functions and |
| 1287 | * (b) always process RX events before TX status events if ordering |
| 1288 | * can be unknown, for example with different interrupt status |
| 1289 | * bits. |
| 1290 | */ |
| 1291 | if (sta->flags & WLAN_STA_PS && |
| 1292 | skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) { |
| 1293 | ieee80211_remove_tx_extra(local, sta->key, skb, |
| 1294 | &status->control); |
| 1295 | skb_queue_tail(&sta->tx_filtered, skb); |
| 1296 | return; |
| 1297 | } |
| 1298 | |
| 1299 | if (!(sta->flags & WLAN_STA_PS) && |
| 1300 | !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) { |
| 1301 | /* Software retry the packet once */ |
| 1302 | status->control.flags |= IEEE80211_TXCTL_REQUEUE; |
| 1303 | ieee80211_remove_tx_extra(local, sta->key, skb, |
| 1304 | &status->control); |
| 1305 | dev_queue_xmit(skb); |
| 1306 | return; |
| 1307 | } |
| 1308 | |
| 1309 | if (net_ratelimit()) |
| 1310 | printk(KERN_DEBUG "%s: dropped TX filtered frame, " |
| 1311 | "queue_len=%d PS=%d @%lu\n", |
| 1312 | wiphy_name(local->hw.wiphy), |
| 1313 | skb_queue_len(&sta->tx_filtered), |
| 1314 | !!(sta->flags & WLAN_STA_PS), jiffies); |
| 1315 | dev_kfree_skb(skb); |
| 1316 | } |
| 1317 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1318 | void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 1319 | struct ieee80211_tx_status *status) |
| 1320 | { |
| 1321 | struct sk_buff *skb2; |
| 1322 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 1323 | struct ieee80211_local *local = hw_to_local(hw); |
| 1324 | u16 frag, type; |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 1325 | struct ieee80211_tx_status_rtap_hdr *rthdr; |
| 1326 | struct ieee80211_sub_if_data *sdata; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1327 | struct net_device *prev_dev = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1328 | |
| 1329 | if (!status) { |
| 1330 | printk(KERN_ERR |
| 1331 | "%s: ieee80211_tx_status called with NULL status\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 1332 | wiphy_name(local->hw.wiphy)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1333 | dev_kfree_skb(skb); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
| 1337 | if (status->excessive_retries) { |
| 1338 | struct sta_info *sta; |
| 1339 | sta = sta_info_get(local, hdr->addr1); |
| 1340 | if (sta) { |
| 1341 | if (sta->flags & WLAN_STA_PS) { |
Johannes Berg | d46e144 | 2008-02-20 23:59:33 +0100 | [diff] [blame] | 1342 | /* |
| 1343 | * The STA is in power save mode, so assume |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1344 | * that this TX packet failed because of that. |
| 1345 | */ |
| 1346 | status->excessive_retries = 0; |
| 1347 | status->flags |= IEEE80211_TX_STATUS_TX_FILTERED; |
Johannes Berg | d46e144 | 2008-02-20 23:59:33 +0100 | [diff] [blame] | 1348 | ieee80211_handle_filtered_frame(local, sta, |
| 1349 | skb, status); |
| 1350 | sta_info_put(sta); |
| 1351 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1352 | } |
| 1353 | sta_info_put(sta); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) { |
| 1358 | struct sta_info *sta; |
| 1359 | sta = sta_info_get(local, hdr->addr1); |
| 1360 | if (sta) { |
Johannes Berg | d46e144 | 2008-02-20 23:59:33 +0100 | [diff] [blame] | 1361 | ieee80211_handle_filtered_frame(local, sta, skb, |
| 1362 | status); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1363 | sta_info_put(sta); |
| 1364 | return; |
| 1365 | } |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 1366 | } else |
| 1367 | rate_control_tx_status(local->mdev, skb, status); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1368 | |
| 1369 | ieee80211_led_tx(local, 0); |
| 1370 | |
| 1371 | /* SNMP counters |
| 1372 | * Fragments are passed to low-level drivers as separate skbs, so these |
| 1373 | * are actually fragments, not frames. Update frame counters only for |
| 1374 | * the first fragment of the frame. */ |
| 1375 | |
| 1376 | frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG; |
| 1377 | type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE; |
| 1378 | |
| 1379 | if (status->flags & IEEE80211_TX_STATUS_ACK) { |
| 1380 | if (frag == 0) { |
| 1381 | local->dot11TransmittedFrameCount++; |
| 1382 | if (is_multicast_ether_addr(hdr->addr1)) |
| 1383 | local->dot11MulticastTransmittedFrameCount++; |
| 1384 | if (status->retry_count > 0) |
| 1385 | local->dot11RetryCount++; |
| 1386 | if (status->retry_count > 1) |
| 1387 | local->dot11MultipleRetryCount++; |
| 1388 | } |
| 1389 | |
| 1390 | /* This counter shall be incremented for an acknowledged MPDU |
| 1391 | * with an individual address in the address 1 field or an MPDU |
| 1392 | * with a multicast address in the address 1 field of type Data |
| 1393 | * or Management. */ |
| 1394 | if (!is_multicast_ether_addr(hdr->addr1) || |
| 1395 | type == IEEE80211_FTYPE_DATA || |
| 1396 | type == IEEE80211_FTYPE_MGMT) |
| 1397 | local->dot11TransmittedFragmentCount++; |
| 1398 | } else { |
| 1399 | if (frag == 0) |
| 1400 | local->dot11FailedCount++; |
| 1401 | } |
| 1402 | |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 1403 | /* this was a transmitted frame, but now we want to reuse it */ |
| 1404 | skb_orphan(skb); |
| 1405 | |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1406 | /* |
| 1407 | * This is a bit racy but we can avoid a lot of work |
| 1408 | * with this test... |
| 1409 | */ |
| 1410 | if (!local->monitors && !local->cooked_mntrs) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1411 | dev_kfree_skb(skb); |
| 1412 | return; |
| 1413 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1414 | |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 1415 | /* send frame to monitor interfaces now */ |
| 1416 | |
| 1417 | if (skb_headroom(skb) < sizeof(*rthdr)) { |
| 1418 | printk(KERN_ERR "ieee80211_tx_status: headroom too small\n"); |
| 1419 | dev_kfree_skb(skb); |
| 1420 | return; |
| 1421 | } |
| 1422 | |
| 1423 | rthdr = (struct ieee80211_tx_status_rtap_hdr*) |
| 1424 | skb_push(skb, sizeof(*rthdr)); |
| 1425 | |
| 1426 | memset(rthdr, 0, sizeof(*rthdr)); |
| 1427 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); |
| 1428 | rthdr->hdr.it_present = |
| 1429 | cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) | |
| 1430 | (1 << IEEE80211_RADIOTAP_DATA_RETRIES)); |
| 1431 | |
| 1432 | if (!(status->flags & IEEE80211_TX_STATUS_ACK) && |
| 1433 | !is_multicast_ether_addr(hdr->addr1)) |
| 1434 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL); |
| 1435 | |
| 1436 | if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) && |
| 1437 | (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) |
| 1438 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS); |
| 1439 | else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) |
| 1440 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS); |
| 1441 | |
| 1442 | rthdr->data_retries = status->retry_count; |
| 1443 | |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1444 | /* XXX: is this sufficient for BPF? */ |
| 1445 | skb_set_mac_header(skb, 0); |
| 1446 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1447 | skb->pkt_type = PACKET_OTHERHOST; |
| 1448 | skb->protocol = htons(ETH_P_802_2); |
| 1449 | memset(skb->cb, 0, sizeof(skb->cb)); |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 1450 | |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1451 | rcu_read_lock(); |
| 1452 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1453 | if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) { |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 1454 | if (!netif_running(sdata->dev)) |
| 1455 | continue; |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1456 | |
| 1457 | if (prev_dev) { |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1458 | skb2 = skb_clone(skb, GFP_ATOMIC); |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1459 | if (skb2) { |
| 1460 | skb2->dev = prev_dev; |
| 1461 | netif_rx(skb2); |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | prev_dev = sdata->dev; |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 1466 | } |
| 1467 | } |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1468 | if (prev_dev) { |
| 1469 | skb->dev = prev_dev; |
| 1470 | netif_rx(skb); |
| 1471 | skb = NULL; |
| 1472 | } |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1473 | rcu_read_unlock(); |
Michael Wu | 3d30d94 | 2008-01-31 19:48:27 +0100 | [diff] [blame] | 1474 | dev_kfree_skb(skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1475 | } |
| 1476 | EXPORT_SYMBOL(ieee80211_tx_status); |
| 1477 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1478 | struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, |
| 1479 | const struct ieee80211_ops *ops) |
| 1480 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1481 | struct ieee80211_local *local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1482 | int priv_size; |
| 1483 | struct wiphy *wiphy; |
| 1484 | |
| 1485 | /* Ensure 32-byte alignment of our private data and hw private data. |
| 1486 | * We use the wiphy priv data for both our ieee80211_local and for |
| 1487 | * the driver's private data |
| 1488 | * |
| 1489 | * In memory it'll be like this: |
| 1490 | * |
| 1491 | * +-------------------------+ |
| 1492 | * | struct wiphy | |
| 1493 | * +-------------------------+ |
| 1494 | * | struct ieee80211_local | |
| 1495 | * +-------------------------+ |
| 1496 | * | driver's private data | |
| 1497 | * +-------------------------+ |
| 1498 | * |
| 1499 | */ |
| 1500 | priv_size = ((sizeof(struct ieee80211_local) + |
| 1501 | NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) + |
| 1502 | priv_data_len; |
| 1503 | |
| 1504 | wiphy = wiphy_new(&mac80211_config_ops, priv_size); |
| 1505 | |
| 1506 | if (!wiphy) |
| 1507 | return NULL; |
| 1508 | |
| 1509 | wiphy->privid = mac80211_wiphy_privid; |
| 1510 | |
| 1511 | local = wiphy_priv(wiphy); |
| 1512 | local->hw.wiphy = wiphy; |
| 1513 | |
| 1514 | local->hw.priv = (char *)local + |
| 1515 | ((sizeof(struct ieee80211_local) + |
| 1516 | NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST); |
| 1517 | |
Johannes Berg | 4480f15c | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1518 | BUG_ON(!ops->tx); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1519 | BUG_ON(!ops->start); |
| 1520 | BUG_ON(!ops->stop); |
Johannes Berg | 4480f15c | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1521 | BUG_ON(!ops->config); |
| 1522 | BUG_ON(!ops->add_interface); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1523 | BUG_ON(!ops->remove_interface); |
| 1524 | BUG_ON(!ops->configure_filter); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1525 | local->ops = ops; |
| 1526 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1527 | local->hw.queues = 1; /* default */ |
| 1528 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1529 | local->bridge_packets = 1; |
| 1530 | |
| 1531 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; |
| 1532 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; |
| 1533 | local->short_retry_limit = 7; |
| 1534 | local->long_retry_limit = 4; |
| 1535 | local->hw.conf.radio_enabled = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1536 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1537 | INIT_LIST_HEAD(&local->interfaces); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1538 | |
| 1539 | INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1540 | |
| 1541 | sta_info_init(local); |
| 1542 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1543 | tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending, |
| 1544 | (unsigned long)local); |
| 1545 | tasklet_disable(&local->tx_pending_tasklet); |
| 1546 | |
| 1547 | tasklet_init(&local->tasklet, |
| 1548 | ieee80211_tasklet_handler, |
| 1549 | (unsigned long) local); |
| 1550 | tasklet_disable(&local->tasklet); |
| 1551 | |
| 1552 | skb_queue_head_init(&local->skb_queue); |
| 1553 | skb_queue_head_init(&local->skb_queue_unreliable); |
| 1554 | |
| 1555 | return local_to_hw(local); |
| 1556 | } |
| 1557 | EXPORT_SYMBOL(ieee80211_alloc_hw); |
| 1558 | |
| 1559 | int ieee80211_register_hw(struct ieee80211_hw *hw) |
| 1560 | { |
| 1561 | struct ieee80211_local *local = hw_to_local(hw); |
| 1562 | const char *name; |
| 1563 | int result; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1564 | enum ieee80211_band band; |
Johannes Berg | 96d5105 | 2008-02-08 09:48:13 +0100 | [diff] [blame] | 1565 | struct net_device *mdev; |
| 1566 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1567 | |
| 1568 | /* |
| 1569 | * generic code guarantees at least one band, |
| 1570 | * set this very early because much code assumes |
| 1571 | * that hw.conf.channel is assigned |
| 1572 | */ |
| 1573 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1574 | struct ieee80211_supported_band *sband; |
| 1575 | |
| 1576 | sband = local->hw.wiphy->bands[band]; |
| 1577 | if (sband) { |
| 1578 | /* init channel we're on */ |
| 1579 | local->hw.conf.channel = |
| 1580 | local->oper_channel = |
| 1581 | local->scan_channel = &sband->channels[0]; |
| 1582 | break; |
| 1583 | } |
| 1584 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1585 | |
| 1586 | result = wiphy_register(local->hw.wiphy); |
| 1587 | if (result < 0) |
| 1588 | return result; |
| 1589 | |
Johannes Berg | 96d5105 | 2008-02-08 09:48:13 +0100 | [diff] [blame] | 1590 | /* for now, mdev needs sub_if_data :/ */ |
| 1591 | mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data), |
| 1592 | "wmaster%d", ether_setup); |
| 1593 | if (!mdev) |
| 1594 | goto fail_mdev_alloc; |
| 1595 | |
| 1596 | sdata = IEEE80211_DEV_TO_SUB_IF(mdev); |
| 1597 | mdev->ieee80211_ptr = &sdata->wdev; |
| 1598 | sdata->wdev.wiphy = local->hw.wiphy; |
| 1599 | |
| 1600 | local->mdev = mdev; |
| 1601 | |
| 1602 | ieee80211_rx_bss_list_init(mdev); |
| 1603 | |
| 1604 | mdev->hard_start_xmit = ieee80211_master_start_xmit; |
| 1605 | mdev->open = ieee80211_master_open; |
| 1606 | mdev->stop = ieee80211_master_stop; |
| 1607 | mdev->type = ARPHRD_IEEE80211; |
| 1608 | mdev->header_ops = &ieee80211_header_ops; |
| 1609 | mdev->set_multicast_list = ieee80211_master_set_multicast_list; |
| 1610 | |
| 1611 | sdata->vif.type = IEEE80211_IF_TYPE_AP; |
| 1612 | sdata->dev = mdev; |
| 1613 | sdata->local = local; |
| 1614 | sdata->u.ap.force_unicast_rateidx = -1; |
| 1615 | sdata->u.ap.max_ratectrl_rateidx = -1; |
| 1616 | ieee80211_if_sdata_init(sdata); |
| 1617 | |
| 1618 | /* no RCU needed since we're still during init phase */ |
| 1619 | list_add_tail(&sdata->list, &local->interfaces); |
| 1620 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1621 | name = wiphy_dev(local->hw.wiphy)->driver->name; |
| 1622 | local->hw.workqueue = create_singlethread_workqueue(name); |
| 1623 | if (!local->hw.workqueue) { |
| 1624 | result = -ENOMEM; |
| 1625 | goto fail_workqueue; |
| 1626 | } |
| 1627 | |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 1628 | /* |
| 1629 | * The hardware needs headroom for sending the frame, |
| 1630 | * and we need some headroom for passing the frame to monitor |
| 1631 | * interfaces, but never both at the same time. |
| 1632 | */ |
Jiri Benc | 33ccad3 | 2007-07-18 17:10:44 +0200 | [diff] [blame] | 1633 | local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom, |
| 1634 | sizeof(struct ieee80211_tx_status_rtap_hdr)); |
Johannes Berg | b306f45 | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 1635 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1636 | debugfs_hw_add(local); |
| 1637 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1638 | local->hw.conf.beacon_int = 1000; |
| 1639 | |
| 1640 | local->wstats_flags |= local->hw.max_rssi ? |
| 1641 | IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID; |
| 1642 | local->wstats_flags |= local->hw.max_signal ? |
| 1643 | IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID; |
| 1644 | local->wstats_flags |= local->hw.max_noise ? |
| 1645 | IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID; |
| 1646 | if (local->hw.max_rssi < 0 || local->hw.max_noise < 0) |
| 1647 | local->wstats_flags |= IW_QUAL_DBM; |
| 1648 | |
| 1649 | result = sta_info_start(local); |
| 1650 | if (result < 0) |
| 1651 | goto fail_sta_info; |
| 1652 | |
| 1653 | rtnl_lock(); |
| 1654 | result = dev_alloc_name(local->mdev, local->mdev->name); |
| 1655 | if (result < 0) |
| 1656 | goto fail_dev; |
| 1657 | |
| 1658 | memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN); |
| 1659 | SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy)); |
| 1660 | |
| 1661 | result = register_netdevice(local->mdev); |
| 1662 | if (result < 0) |
| 1663 | goto fail_dev; |
| 1664 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1665 | ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev)); |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 1666 | ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1667 | |
Johannes Berg | 830f903 | 2007-10-28 14:51:05 +0100 | [diff] [blame] | 1668 | result = ieee80211_init_rate_ctrl_alg(local, |
| 1669 | hw->rate_control_algorithm); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1670 | if (result < 0) { |
| 1671 | printk(KERN_DEBUG "%s: Failed to initialize rate control " |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 1672 | "algorithm\n", wiphy_name(local->hw.wiphy)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1673 | goto fail_rate; |
| 1674 | } |
| 1675 | |
| 1676 | result = ieee80211_wep_init(local); |
| 1677 | |
| 1678 | if (result < 0) { |
| 1679 | printk(KERN_DEBUG "%s: Failed to initialize wep\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 1680 | wiphy_name(local->hw.wiphy)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1681 | goto fail_wep; |
| 1682 | } |
| 1683 | |
| 1684 | ieee80211_install_qdisc(local->mdev); |
| 1685 | |
| 1686 | /* add one default STA interface */ |
| 1687 | result = ieee80211_if_add(local->mdev, "wlan%d", NULL, |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 1688 | IEEE80211_IF_TYPE_STA, NULL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1689 | if (result) |
| 1690 | printk(KERN_WARNING "%s: Failed to add default virtual iface\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 1691 | wiphy_name(local->hw.wiphy)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1692 | |
| 1693 | local->reg_state = IEEE80211_DEV_REGISTERED; |
| 1694 | rtnl_unlock(); |
| 1695 | |
| 1696 | ieee80211_led_init(local); |
| 1697 | |
| 1698 | return 0; |
| 1699 | |
| 1700 | fail_wep: |
| 1701 | rate_control_deinitialize(local); |
| 1702 | fail_rate: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1703 | ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1704 | unregister_netdevice(local->mdev); |
| 1705 | fail_dev: |
| 1706 | rtnl_unlock(); |
| 1707 | sta_info_stop(local); |
| 1708 | fail_sta_info: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1709 | debugfs_hw_del(local); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1710 | destroy_workqueue(local->hw.workqueue); |
| 1711 | fail_workqueue: |
Johannes Berg | 96d5105 | 2008-02-08 09:48:13 +0100 | [diff] [blame] | 1712 | ieee80211_if_free(local->mdev); |
| 1713 | local->mdev = NULL; |
| 1714 | fail_mdev_alloc: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1715 | wiphy_unregister(local->hw.wiphy); |
| 1716 | return result; |
| 1717 | } |
| 1718 | EXPORT_SYMBOL(ieee80211_register_hw); |
| 1719 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1720 | void ieee80211_unregister_hw(struct ieee80211_hw *hw) |
| 1721 | { |
| 1722 | struct ieee80211_local *local = hw_to_local(hw); |
| 1723 | struct ieee80211_sub_if_data *sdata, *tmp; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1724 | |
| 1725 | tasklet_kill(&local->tx_pending_tasklet); |
| 1726 | tasklet_kill(&local->tasklet); |
| 1727 | |
| 1728 | rtnl_lock(); |
| 1729 | |
| 1730 | BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED); |
| 1731 | |
| 1732 | local->reg_state = IEEE80211_DEV_UNREGISTERED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1733 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1734 | /* |
| 1735 | * At this point, interface list manipulations are fine |
| 1736 | * because the driver cannot be handing us frames any |
| 1737 | * more and the tasklet is killed. |
| 1738 | */ |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 1739 | |
| 1740 | /* |
| 1741 | * First, we remove all non-master interfaces. Do this because they |
| 1742 | * may have bss pointer dependency on the master, and when we free |
| 1743 | * the master these would be freed as well, breaking our list |
| 1744 | * iteration completely. |
| 1745 | */ |
| 1746 | list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) { |
| 1747 | if (sdata->dev == local->mdev) |
| 1748 | continue; |
| 1749 | list_del(&sdata->list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1750 | __ieee80211_if_del(local, sdata); |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | /* then, finally, remove the master interface */ |
| 1754 | __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1755 | |
| 1756 | rtnl_unlock(); |
| 1757 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1758 | ieee80211_rx_bss_list_deinit(local->mdev); |
| 1759 | ieee80211_clear_tx_pending(local); |
| 1760 | sta_info_stop(local); |
| 1761 | rate_control_deinitialize(local); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1762 | debugfs_hw_del(local); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1763 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1764 | if (skb_queue_len(&local->skb_queue) |
| 1765 | || skb_queue_len(&local->skb_queue_unreliable)) |
| 1766 | printk(KERN_WARNING "%s: skb_queue not empty\n", |
Johannes Berg | dd1cd4c | 2007-09-18 17:29:20 -0400 | [diff] [blame] | 1767 | wiphy_name(local->hw.wiphy)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1768 | skb_queue_purge(&local->skb_queue); |
| 1769 | skb_queue_purge(&local->skb_queue_unreliable); |
| 1770 | |
| 1771 | destroy_workqueue(local->hw.workqueue); |
| 1772 | wiphy_unregister(local->hw.wiphy); |
| 1773 | ieee80211_wep_free(local); |
| 1774 | ieee80211_led_exit(local); |
Johannes Berg | 96d5105 | 2008-02-08 09:48:13 +0100 | [diff] [blame] | 1775 | ieee80211_if_free(local->mdev); |
| 1776 | local->mdev = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1777 | } |
| 1778 | EXPORT_SYMBOL(ieee80211_unregister_hw); |
| 1779 | |
| 1780 | void ieee80211_free_hw(struct ieee80211_hw *hw) |
| 1781 | { |
| 1782 | struct ieee80211_local *local = hw_to_local(hw); |
| 1783 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1784 | wiphy_free(local->hw.wiphy); |
| 1785 | } |
| 1786 | EXPORT_SYMBOL(ieee80211_free_hw); |
| 1787 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1788 | static int __init ieee80211_init(void) |
| 1789 | { |
| 1790 | struct sk_buff *skb; |
| 1791 | int ret; |
| 1792 | |
| 1793 | BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb)); |
| 1794 | |
Johannes Berg | 4b47589 | 2008-01-02 15:17:03 +0100 | [diff] [blame] | 1795 | ret = rc80211_simple_init(); |
Johannes Berg | ac71c69 | 2007-10-28 14:17:44 +0100 | [diff] [blame] | 1796 | if (ret) |
Johannes Berg | 3eadf5f | 2008-01-31 19:33:53 +0100 | [diff] [blame] | 1797 | goto out; |
Mattias Nissler | ad01837 | 2007-12-19 01:25:57 +0100 | [diff] [blame] | 1798 | |
Johannes Berg | 4b47589 | 2008-01-02 15:17:03 +0100 | [diff] [blame] | 1799 | ret = rc80211_pid_init(); |
Mattias Nissler | ad01837 | 2007-12-19 01:25:57 +0100 | [diff] [blame] | 1800 | if (ret) |
Johannes Berg | 3eadf5f | 2008-01-31 19:33:53 +0100 | [diff] [blame] | 1801 | goto out_cleanup_simple; |
Johannes Berg | ac71c69 | 2007-10-28 14:17:44 +0100 | [diff] [blame] | 1802 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1803 | ret = ieee80211_wme_register(); |
| 1804 | if (ret) { |
| 1805 | printk(KERN_DEBUG "ieee80211_init: failed to " |
| 1806 | "initialize WME (err=%d)\n", ret); |
Johannes Berg | 3eadf5f | 2008-01-31 19:33:53 +0100 | [diff] [blame] | 1807 | goto out_cleanup_pid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1810 | ieee80211_debugfs_netdev_init(); |
| 1811 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1812 | return 0; |
Mattias Nissler | ad01837 | 2007-12-19 01:25:57 +0100 | [diff] [blame] | 1813 | |
Johannes Berg | 3eadf5f | 2008-01-31 19:33:53 +0100 | [diff] [blame] | 1814 | out_cleanup_pid: |
Johannes Berg | 4b47589 | 2008-01-02 15:17:03 +0100 | [diff] [blame] | 1815 | rc80211_pid_exit(); |
Johannes Berg | 3eadf5f | 2008-01-31 19:33:53 +0100 | [diff] [blame] | 1816 | out_cleanup_simple: |
| 1817 | rc80211_simple_exit(); |
| 1818 | out: |
Mattias Nissler | ad01837 | 2007-12-19 01:25:57 +0100 | [diff] [blame] | 1819 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1822 | static void __exit ieee80211_exit(void) |
| 1823 | { |
Johannes Berg | 4b47589 | 2008-01-02 15:17:03 +0100 | [diff] [blame] | 1824 | rc80211_simple_exit(); |
| 1825 | rc80211_pid_exit(); |
Johannes Berg | ac71c69 | 2007-10-28 14:17:44 +0100 | [diff] [blame] | 1826 | |
Luis Carlos Cobo | f7a9214 | 2008-02-23 15:17:18 +0100 | [diff] [blame^] | 1827 | #ifdef CONFIG_MAC80211_MESH |
| 1828 | if (mesh_allocated) |
| 1829 | ieee80211s_stop(); |
| 1830 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1831 | ieee80211_wme_unregister(); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 1832 | ieee80211_debugfs_netdev_exit(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | |
Johannes Berg | ca9938f | 2007-09-11 12:50:32 +0200 | [diff] [blame] | 1836 | subsys_initcall(ieee80211_init); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1837 | module_exit(ieee80211_exit); |
| 1838 | |
| 1839 | MODULE_DESCRIPTION("IEEE 802.11 subsystem"); |
| 1840 | MODULE_LICENSE("GPL"); |