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