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