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