Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 2 | * Interface handling (except master interface) |
| 3 | * |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 5 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 6 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 7 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/if_arp.h> |
| 16 | #include <linux/netdevice.h> |
| 17 | #include <linux/rtnetlink.h> |
| 18 | #include <net/mac80211.h> |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 19 | #include <net/ieee80211_radiotap.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 20 | #include "ieee80211_i.h" |
| 21 | #include "sta_info.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 22 | #include "debugfs_netdev.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 23 | #include "mesh.h" |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 24 | #include "led.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 25 | #include "driver-ops.h" |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 26 | #include "wme.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 27 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 28 | /** |
| 29 | * DOC: Interface list locking |
| 30 | * |
| 31 | * The interface list in each struct ieee80211_local is protected |
| 32 | * three-fold: |
| 33 | * |
| 34 | * (1) modifications may only be done under the RTNL |
| 35 | * (2) modifications and readers are protected against each other by |
| 36 | * the iflist_mtx. |
| 37 | * (3) modifications are done in an RCU manner so atomic readers |
| 38 | * can traverse the list in RCU-safe blocks. |
| 39 | * |
| 40 | * As a consequence, reads (traversals) of the list can be protected |
| 41 | * by either the RTNL, the iflist_mtx or RCU. |
| 42 | */ |
| 43 | |
| 44 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 45 | static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) |
| 46 | { |
| 47 | int meshhdrlen; |
| 48 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 49 | |
| 50 | meshhdrlen = (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) ? 5 : 0; |
| 51 | |
| 52 | /* FIX: what would be proper limits for MTU? |
| 53 | * This interface uses 802.3 frames. */ |
| 54 | if (new_mtu < 256 || |
| 55 | new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) { |
| 56 | return -EINVAL; |
| 57 | } |
| 58 | |
| 59 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 60 | printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu); |
| 61 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 62 | dev->mtu = new_mtu; |
| 63 | return 0; |
| 64 | } |
| 65 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 66 | static int ieee80211_change_mac(struct net_device *dev, void *addr) |
| 67 | { |
| 68 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Kalle Valo | fc5f757 | 2009-12-30 15:54:03 +0200 | [diff] [blame] | 69 | struct sockaddr *sa = addr; |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 70 | int ret; |
| 71 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 72 | if (ieee80211_sdata_running(sdata)) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 73 | return -EBUSY; |
| 74 | |
Kalle Valo | fc5f757 | 2009-12-30 15:54:03 +0200 | [diff] [blame] | 75 | ret = eth_mac_addr(dev, sa); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 76 | |
| 77 | if (ret == 0) |
Kalle Valo | fc5f757 | 2009-12-30 15:54:03 +0200 | [diff] [blame] | 78 | memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 79 | |
| 80 | return ret; |
| 81 | } |
| 82 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 83 | static inline int identical_mac_addr_allowed(int type1, int type2) |
| 84 | { |
| 85 | return type1 == NL80211_IFTYPE_MONITOR || |
| 86 | type2 == NL80211_IFTYPE_MONITOR || |
| 87 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) || |
| 88 | (type1 == NL80211_IFTYPE_WDS && |
| 89 | (type2 == NL80211_IFTYPE_WDS || |
| 90 | type2 == NL80211_IFTYPE_AP)) || |
| 91 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) || |
| 92 | (type1 == NL80211_IFTYPE_AP_VLAN && |
| 93 | (type2 == NL80211_IFTYPE_AP || |
| 94 | type2 == NL80211_IFTYPE_AP_VLAN)); |
| 95 | } |
| 96 | |
| 97 | static int ieee80211_open(struct net_device *dev) |
| 98 | { |
Johannes Berg | b4a4bf5 | 2008-09-26 13:34:54 +0200 | [diff] [blame] | 99 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 100 | struct ieee80211_sub_if_data *nsdata; |
| 101 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 102 | struct sta_info *sta; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 103 | u32 changed = 0; |
| 104 | int res; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 105 | u32 hw_reconf_flags = 0; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 106 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 107 | /* fail early if user set an invalid address */ |
Johannes Berg | bf533e0 | 2010-08-27 12:35:56 +0200 | [diff] [blame^] | 108 | if (!is_zero_ether_addr(dev->dev_addr) && |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 109 | !is_valid_ether_addr(dev->dev_addr)) |
| 110 | return -EADDRNOTAVAIL; |
| 111 | |
| 112 | /* we hold the RTNL here so can safely walk the list */ |
| 113 | list_for_each_entry(nsdata, &local->interfaces, list) { |
| 114 | struct net_device *ndev = nsdata->dev; |
| 115 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 116 | if (ndev != dev && ieee80211_sdata_running(nsdata)) { |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 117 | /* |
| 118 | * Allow only a single IBSS interface to be up at any |
| 119 | * time. This is restricted because beacon distribution |
| 120 | * cannot work properly if both are in the same IBSS. |
| 121 | * |
| 122 | * To remove this restriction we'd have to disallow them |
| 123 | * from setting the same SSID on different IBSS interfaces |
| 124 | * belonging to the same hardware. Then, however, we're |
| 125 | * faced with having to adopt two different TSF timers... |
| 126 | */ |
| 127 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
| 128 | nsdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 129 | return -EBUSY; |
| 130 | |
| 131 | /* |
| 132 | * The remaining checks are only performed for interfaces |
| 133 | * with the same MAC address. |
| 134 | */ |
| 135 | if (compare_ether_addr(dev->dev_addr, ndev->dev_addr)) |
| 136 | continue; |
| 137 | |
| 138 | /* |
| 139 | * check whether it may have the same address |
| 140 | */ |
| 141 | if (!identical_mac_addr_allowed(sdata->vif.type, |
| 142 | nsdata->vif.type)) |
| 143 | return -ENOTUNIQ; |
| 144 | |
| 145 | /* |
| 146 | * can only add VLANs to enabled APs |
| 147 | */ |
| 148 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
| 149 | nsdata->vif.type == NL80211_IFTYPE_AP) |
| 150 | sdata->bss = &nsdata->u.ap; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | switch (sdata->vif.type) { |
| 155 | case NL80211_IFTYPE_WDS: |
| 156 | if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) |
| 157 | return -ENOLINK; |
| 158 | break; |
| 159 | case NL80211_IFTYPE_AP_VLAN: |
| 160 | if (!sdata->bss) |
| 161 | return -ENOLINK; |
| 162 | list_add(&sdata->u.vlan.list, &sdata->bss->vlans); |
| 163 | break; |
| 164 | case NL80211_IFTYPE_AP: |
| 165 | sdata->bss = &sdata->u.ap; |
| 166 | break; |
| 167 | case NL80211_IFTYPE_MESH_POINT: |
| 168 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
| 169 | break; |
| 170 | /* mesh ifaces must set allmulti to forward mcast traffic */ |
| 171 | atomic_inc(&local->iff_allmultis); |
| 172 | break; |
| 173 | case NL80211_IFTYPE_STATION: |
| 174 | case NL80211_IFTYPE_MONITOR: |
| 175 | case NL80211_IFTYPE_ADHOC: |
| 176 | /* no special treatment */ |
| 177 | break; |
| 178 | case NL80211_IFTYPE_UNSPECIFIED: |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 179 | case NUM_NL80211_IFTYPES: |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 180 | /* cannot happen */ |
| 181 | WARN_ON(1); |
| 182 | break; |
| 183 | } |
| 184 | |
| 185 | if (local->open_count == 0) { |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 186 | res = drv_start(local); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 187 | if (res) |
| 188 | goto err_del_bss; |
John W. Linville | 4e6cbfd | 2010-07-29 16:14:13 -0400 | [diff] [blame] | 189 | if (local->ops->napi_poll) |
| 190 | napi_enable(&local->napi); |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 191 | /* we're brought up, everything changes */ |
| 192 | hw_reconf_flags = ~0; |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 193 | ieee80211_led_radio(local, true); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
Johannes Berg | bf533e0 | 2010-08-27 12:35:56 +0200 | [diff] [blame^] | 197 | * Copy the hopefully now-present MAC address to |
| 198 | * this interface, if it has the special null one. |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 199 | */ |
Johannes Berg | bf533e0 | 2010-08-27 12:35:56 +0200 | [diff] [blame^] | 200 | if (is_zero_ether_addr(dev->dev_addr)) { |
| 201 | memcpy(dev->dev_addr, |
| 202 | local->hw.wiphy->perm_addr, |
| 203 | ETH_ALEN); |
| 204 | memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 205 | |
Johannes Berg | bf533e0 | 2010-08-27 12:35:56 +0200 | [diff] [blame^] | 206 | if (!is_valid_ether_addr(dev->dev_addr)) { |
| 207 | if (!local->open_count) |
| 208 | drv_stop(local); |
| 209 | return -EADDRNOTAVAIL; |
John W. Linville | 0adc23f | 2009-10-06 16:27:18 -0400 | [diff] [blame] | 210 | } |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 213 | switch (sdata->vif.type) { |
| 214 | case NL80211_IFTYPE_AP_VLAN: |
| 215 | /* no need to tell driver */ |
| 216 | break; |
| 217 | case NL80211_IFTYPE_MONITOR: |
| 218 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
| 219 | local->cooked_mntrs++; |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | /* must be before the call to ieee80211_configure_filter */ |
| 224 | local->monitors++; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 225 | if (local->monitors == 1) { |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 226 | local->hw.conf.flags |= IEEE80211_CONF_MONITOR; |
| 227 | hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 228 | } |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 229 | |
| 230 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) |
| 231 | local->fif_fcsfail++; |
| 232 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) |
| 233 | local->fif_plcpfail++; |
Igor Perminov | e3b90ca | 2009-08-04 16:48:51 +0400 | [diff] [blame] | 234 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) { |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 235 | local->fif_control++; |
Igor Perminov | e3b90ca | 2009-08-04 16:48:51 +0400 | [diff] [blame] | 236 | local->fif_pspoll++; |
| 237 | } |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 238 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) |
| 239 | local->fif_other_bss++; |
| 240 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 241 | ieee80211_configure_filter(local); |
David Gnedt | 53e9b1d | 2010-07-19 20:44:02 +0200 | [diff] [blame] | 242 | |
| 243 | netif_carrier_on(dev); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 244 | break; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 245 | default: |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 246 | res = drv_add_interface(local, &sdata->vif); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 247 | if (res) |
| 248 | goto err_stop; |
| 249 | |
Andrey Yurovsky | a3c9aa5 | 2008-10-31 14:50:12 -0700 | [diff] [blame] | 250 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
| 251 | local->fif_other_bss++; |
Andrey Yurovsky | a3c9aa5 | 2008-10-31 14:50:12 -0700 | [diff] [blame] | 252 | ieee80211_configure_filter(local); |
Andrey Yurovsky | a3c9aa5 | 2008-10-31 14:50:12 -0700 | [diff] [blame] | 253 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 254 | ieee80211_start_mesh(sdata); |
Igor Perminov | e3b90ca | 2009-08-04 16:48:51 +0400 | [diff] [blame] | 255 | } else if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 256 | local->fif_pspoll++; |
| 257 | |
Igor Perminov | e3b90ca | 2009-08-04 16:48:51 +0400 | [diff] [blame] | 258 | ieee80211_configure_filter(local); |
Andrey Yurovsky | a3c9aa5 | 2008-10-31 14:50:12 -0700 | [diff] [blame] | 259 | } |
Igor Perminov | e3b90ca | 2009-08-04 16:48:51 +0400 | [diff] [blame] | 260 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 261 | changed |= ieee80211_reset_erp_info(sdata); |
| 262 | ieee80211_bss_info_change_notify(sdata, changed); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 263 | |
Johannes Berg | 7986cf9 | 2009-03-21 17:08:43 +0100 | [diff] [blame] | 264 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 265 | netif_carrier_off(dev); |
| 266 | else |
| 267 | netif_carrier_on(dev); |
| 268 | } |
| 269 | |
| 270 | if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
| 271 | /* Create STA entry for the WDS peer */ |
| 272 | sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, |
| 273 | GFP_KERNEL); |
| 274 | if (!sta) { |
| 275 | res = -ENOMEM; |
| 276 | goto err_del_interface; |
| 277 | } |
| 278 | |
| 279 | /* no locking required since STA is not live yet */ |
| 280 | sta->flags |= WLAN_STA_AUTHORIZED; |
| 281 | |
| 282 | res = sta_info_insert(sta); |
| 283 | if (res) { |
| 284 | /* STA has been freed */ |
| 285 | goto err_del_interface; |
| 286 | } |
| 287 | } |
| 288 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 289 | /* |
| 290 | * set_multicast_list will be invoked by the networking core |
| 291 | * which will check whether any increments here were done in |
| 292 | * error and sync them down to the hardware as filter flags. |
| 293 | */ |
| 294 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) |
| 295 | atomic_inc(&local->iff_allmultis); |
| 296 | |
| 297 | if (sdata->flags & IEEE80211_SDATA_PROMISC) |
| 298 | atomic_inc(&local->iff_promiscs); |
| 299 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 300 | mutex_lock(&local->mtx); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 301 | hw_reconf_flags |= __ieee80211_recalc_idle(local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 302 | mutex_unlock(&local->mtx); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 303 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 304 | local->open_count++; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 305 | if (hw_reconf_flags) { |
| 306 | ieee80211_hw_config(local, hw_reconf_flags); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 307 | /* |
| 308 | * set default queue parameters so drivers don't |
| 309 | * need to initialise the hardware if the hardware |
| 310 | * doesn't start up with sane defaults |
| 311 | */ |
| 312 | ieee80211_set_wmm_default(sdata); |
| 313 | } |
| 314 | |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 315 | ieee80211_recalc_ps(local, -1); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 316 | |
John W. Linville | 8a5b33f | 2010-01-06 15:39:39 -0500 | [diff] [blame] | 317 | netif_tx_start_all_queues(dev); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 318 | |
| 319 | return 0; |
| 320 | err_del_interface: |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 321 | drv_remove_interface(local, &sdata->vif); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 322 | err_stop: |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 323 | if (!local->open_count) |
| 324 | drv_stop(local); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 325 | err_del_bss: |
| 326 | sdata->bss = NULL; |
| 327 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 328 | list_del(&sdata->u.vlan.list); |
| 329 | return res; |
| 330 | } |
| 331 | |
| 332 | static int ieee80211_stop(struct net_device *dev) |
| 333 | { |
| 334 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 335 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 336 | unsigned long flags; |
| 337 | struct sk_buff *skb, *tmp; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 338 | u32 hw_reconf_flags = 0; |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 339 | int i; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * Stop TX on this interface first. |
| 343 | */ |
John W. Linville | 8a5b33f | 2010-01-06 15:39:39 -0500 | [diff] [blame] | 344 | netif_tx_stop_all_queues(dev); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 345 | |
| 346 | /* |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 347 | * Purge work for this interface. |
| 348 | */ |
| 349 | ieee80211_work_purge(sdata); |
| 350 | |
| 351 | /* |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 352 | * Remove all stations associated with this interface. |
| 353 | * |
| 354 | * This must be done before calling ops->remove_interface() |
| 355 | * because otherwise we can later invoke ops->sta_notify() |
| 356 | * whenever the STAs are removed, and that invalidates driver |
| 357 | * assumptions about always getting a vif pointer that is valid |
| 358 | * (because if we remove a STA after ops->remove_interface() |
| 359 | * the driver will have removed the vif info already!) |
| 360 | * |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 361 | * This is relevant only in AP, WDS and mesh modes, since in |
| 362 | * all other modes we've already removed all stations when |
| 363 | * disconnecting etc. |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 364 | */ |
| 365 | sta_info_flush(local, sdata); |
| 366 | |
| 367 | /* |
| 368 | * Don't count this interface for promisc/allmulti while it |
| 369 | * is down. dev_mc_unsync() will invoke set_multicast_list |
| 370 | * on the master interface which will sync these down to the |
| 371 | * hardware as filter flags. |
| 372 | */ |
| 373 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) |
| 374 | atomic_dec(&local->iff_allmultis); |
| 375 | |
| 376 | if (sdata->flags & IEEE80211_SDATA_PROMISC) |
| 377 | atomic_dec(&local->iff_promiscs); |
| 378 | |
Igor Perminov | e3b90ca | 2009-08-04 16:48:51 +0400 | [diff] [blame] | 379 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 380 | local->fif_pspoll--; |
| 381 | |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 382 | netif_addr_lock_bh(dev); |
| 383 | spin_lock_bh(&local->filter_lock); |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 384 | __hw_addr_unsync(&local->mc_list, &dev->mc, dev->addr_len); |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 385 | spin_unlock_bh(&local->filter_lock); |
| 386 | netif_addr_unlock_bh(dev); |
| 387 | |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 388 | ieee80211_configure_filter(local); |
| 389 | |
Vivek Natarajan | 7cbf0ba | 2008-12-24 00:34:37 -0800 | [diff] [blame] | 390 | del_timer_sync(&local->dynamic_ps_timer); |
| 391 | cancel_work_sync(&local->dynamic_ps_enable_work); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 392 | |
| 393 | /* APs need special treatment */ |
| 394 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
Johannes Berg | 57c9fff | 2009-07-29 15:46:21 +0200 | [diff] [blame] | 395 | struct ieee80211_sub_if_data *vlan, *tmpsdata; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 396 | struct beacon_data *old_beacon = sdata->u.ap.beacon; |
| 397 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 398 | /* sdata_running will return false, so this will disable */ |
| 399 | ieee80211_bss_info_change_notify(sdata, |
| 400 | BSS_CHANGED_BEACON_ENABLED); |
| 401 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 402 | /* remove beacon */ |
| 403 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 404 | synchronize_rcu(); |
| 405 | kfree(old_beacon); |
| 406 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 407 | /* free all potentially still buffered bcast frames */ |
| 408 | while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) { |
| 409 | local->total_ps_buffered--; |
| 410 | dev_kfree_skb(skb); |
| 411 | } |
| 412 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 413 | /* down all dependent devices, that is VLANs */ |
Johannes Berg | 57c9fff | 2009-07-29 15:46:21 +0200 | [diff] [blame] | 414 | list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans, |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 415 | u.vlan.list) |
| 416 | dev_close(vlan->dev); |
| 417 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); |
| 418 | } |
| 419 | |
| 420 | local->open_count--; |
| 421 | |
| 422 | switch (sdata->vif.type) { |
| 423 | case NL80211_IFTYPE_AP_VLAN: |
| 424 | list_del(&sdata->u.vlan.list); |
| 425 | /* no need to tell driver */ |
| 426 | break; |
| 427 | case NL80211_IFTYPE_MONITOR: |
| 428 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
| 429 | local->cooked_mntrs--; |
| 430 | break; |
| 431 | } |
| 432 | |
| 433 | local->monitors--; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 434 | if (local->monitors == 0) { |
Johannes Berg | 0869aea | 2009-10-28 10:03:35 +0100 | [diff] [blame] | 435 | local->hw.conf.flags &= ~IEEE80211_CONF_MONITOR; |
| 436 | hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 437 | } |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 438 | |
| 439 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) |
| 440 | local->fif_fcsfail--; |
| 441 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) |
| 442 | local->fif_plcpfail--; |
Igor Perminov | e3b90ca | 2009-08-04 16:48:51 +0400 | [diff] [blame] | 443 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) { |
| 444 | local->fif_pspoll--; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 445 | local->fif_control--; |
Igor Perminov | e3b90ca | 2009-08-04 16:48:51 +0400 | [diff] [blame] | 446 | } |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 447 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) |
| 448 | local->fif_other_bss--; |
| 449 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 450 | ieee80211_configure_filter(local); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 451 | break; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 452 | case NL80211_IFTYPE_MESH_POINT: |
| 453 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
Andrey Yurovsky | a3c9aa5 | 2008-10-31 14:50:12 -0700 | [diff] [blame] | 454 | /* other_bss and allmulti are always set on mesh |
| 455 | * ifaces */ |
| 456 | local->fif_other_bss--; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 457 | atomic_dec(&local->iff_allmultis); |
Andrey Yurovsky | a3c9aa5 | 2008-10-31 14:50:12 -0700 | [diff] [blame] | 458 | |
Andrey Yurovsky | a3c9aa5 | 2008-10-31 14:50:12 -0700 | [diff] [blame] | 459 | ieee80211_configure_filter(local); |
Andrey Yurovsky | a3c9aa5 | 2008-10-31 14:50:12 -0700 | [diff] [blame] | 460 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 461 | ieee80211_stop_mesh(sdata); |
| 462 | } |
| 463 | /* fall through */ |
| 464 | default: |
Johannes Berg | c1475ca | 2010-06-10 10:21:37 +0200 | [diff] [blame] | 465 | flush_work(&sdata->work); |
Johannes Berg | 35f20c1 | 2010-06-10 10:21:30 +0200 | [diff] [blame] | 466 | /* |
| 467 | * When we get here, the interface is marked down. |
| 468 | * Call synchronize_rcu() to wait for the RX path |
| 469 | * should it be using the interface and enqueuing |
| 470 | * frames at this very time on another CPU. |
| 471 | */ |
| 472 | synchronize_rcu(); |
| 473 | skb_queue_purge(&sdata->skb_queue); |
| 474 | |
Johannes Berg | 15db0b7 | 2009-08-25 16:33:47 +0200 | [diff] [blame] | 475 | if (local->scan_sdata == sdata) |
| 476 | ieee80211_scan_cancel(local); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 477 | |
Bob Copeland | 97af743 | 2009-07-29 10:13:03 +0200 | [diff] [blame] | 478 | /* |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 479 | * Disable beaconing here for mesh only, AP and IBSS |
| 480 | * are already taken care of. |
Bob Copeland | 97af743 | 2009-07-29 10:13:03 +0200 | [diff] [blame] | 481 | */ |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 482 | if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
Bob Copeland | 97af743 | 2009-07-29 10:13:03 +0200 | [diff] [blame] | 483 | ieee80211_bss_info_change_notify(sdata, |
| 484 | BSS_CHANGED_BEACON_ENABLED); |
Bob Copeland | 97af743 | 2009-07-29 10:13:03 +0200 | [diff] [blame] | 485 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 486 | /* |
| 487 | * Free all remaining keys, there shouldn't be any, |
| 488 | * except maybe group keys in AP more or WDS? |
| 489 | */ |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 490 | ieee80211_free_keys(sdata); |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 491 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 492 | drv_remove_interface(local, &sdata->vif); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | sdata->bss = NULL; |
| 496 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 497 | mutex_lock(&local->mtx); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 498 | hw_reconf_flags |= __ieee80211_recalc_idle(local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 499 | mutex_unlock(&local->mtx); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 500 | |
| 501 | ieee80211_recalc_ps(local, -1); |
| 502 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 503 | if (local->open_count == 0) { |
John W. Linville | 4e6cbfd | 2010-07-29 16:14:13 -0400 | [diff] [blame] | 504 | if (local->ops->napi_poll) |
| 505 | napi_disable(&local->napi); |
Johannes Berg | ea77f12 | 2009-08-21 14:44:45 +0200 | [diff] [blame] | 506 | ieee80211_clear_tx_pending(local); |
Johannes Berg | 84f6a01 | 2009-08-20 20:02:20 +0200 | [diff] [blame] | 507 | ieee80211_stop_device(local); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 508 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 509 | /* no reconfiguring after stop! */ |
| 510 | hw_reconf_flags = 0; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 513 | /* do after stop to avoid reconfiguring when we stop anyway */ |
| 514 | if (hw_reconf_flags) |
| 515 | ieee80211_hw_config(local, hw_reconf_flags); |
| 516 | |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 517 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 518 | for (i = 0; i < IEEE80211_MAX_QUEUES; i++) { |
| 519 | skb_queue_walk_safe(&local->pending[i], skb, tmp) { |
| 520 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 521 | if (info->control.vif == &sdata->vif) { |
| 522 | __skb_unlink(skb, &local->pending[i]); |
| 523 | dev_kfree_skb_irq(skb); |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 528 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static void ieee80211_set_multicast_list(struct net_device *dev) |
| 533 | { |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 534 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | b4a4bf5 | 2008-09-26 13:34:54 +0200 | [diff] [blame] | 535 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 536 | int allmulti, promisc, sdata_allmulti, sdata_promisc; |
| 537 | |
| 538 | allmulti = !!(dev->flags & IFF_ALLMULTI); |
| 539 | promisc = !!(dev->flags & IFF_PROMISC); |
| 540 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); |
| 541 | sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC); |
| 542 | |
| 543 | if (allmulti != sdata_allmulti) { |
| 544 | if (dev->flags & IFF_ALLMULTI) |
| 545 | atomic_inc(&local->iff_allmultis); |
| 546 | else |
| 547 | atomic_dec(&local->iff_allmultis); |
| 548 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; |
| 549 | } |
| 550 | |
| 551 | if (promisc != sdata_promisc) { |
| 552 | if (dev->flags & IFF_PROMISC) |
| 553 | atomic_inc(&local->iff_promiscs); |
| 554 | else |
| 555 | atomic_dec(&local->iff_promiscs); |
| 556 | sdata->flags ^= IEEE80211_SDATA_PROMISC; |
| 557 | } |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 558 | spin_lock_bh(&local->filter_lock); |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 559 | __hw_addr_sync(&local->mc_list, &dev->mc, dev->addr_len); |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 560 | spin_unlock_bh(&local->filter_lock); |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 561 | ieee80211_queue_work(&local->hw, &local->reconfig_filter); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 562 | } |
| 563 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 564 | /* |
| 565 | * Called when the netdev is removed or, by the code below, before |
| 566 | * the interface type changes. |
| 567 | */ |
| 568 | static void ieee80211_teardown_sdata(struct net_device *dev) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 569 | { |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 570 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 571 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 572 | int flushed; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 573 | int i; |
| 574 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 575 | /* free extra data */ |
| 576 | ieee80211_free_keys(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 577 | |
Jouni Malinen | aee14ce | 2008-09-09 16:33:15 +0200 | [diff] [blame] | 578 | ieee80211_debugfs_remove_netdev(sdata); |
| 579 | |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 580 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 581 | __skb_queue_purge(&sdata->fragments[i].skb_list); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 582 | sdata->fragment_next = 0; |
| 583 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 584 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 585 | mesh_rmc_free(sdata); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 586 | |
| 587 | flushed = sta_info_flush(local, sdata); |
| 588 | WARN_ON(flushed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 591 | static u16 ieee80211_netdev_select_queue(struct net_device *dev, |
| 592 | struct sk_buff *skb) |
| 593 | { |
| 594 | return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb); |
| 595 | } |
| 596 | |
Johannes Berg | 587e729 | 2009-01-30 13:35:22 +0100 | [diff] [blame] | 597 | static const struct net_device_ops ieee80211_dataif_ops = { |
| 598 | .ndo_open = ieee80211_open, |
| 599 | .ndo_stop = ieee80211_stop, |
| 600 | .ndo_uninit = ieee80211_teardown_sdata, |
| 601 | .ndo_start_xmit = ieee80211_subif_start_xmit, |
| 602 | .ndo_set_multicast_list = ieee80211_set_multicast_list, |
| 603 | .ndo_change_mtu = ieee80211_change_mtu, |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 604 | .ndo_set_mac_address = ieee80211_change_mac, |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 605 | .ndo_select_queue = ieee80211_netdev_select_queue, |
Johannes Berg | 587e729 | 2009-01-30 13:35:22 +0100 | [diff] [blame] | 606 | }; |
| 607 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 608 | static u16 ieee80211_monitor_select_queue(struct net_device *dev, |
| 609 | struct sk_buff *skb) |
| 610 | { |
| 611 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 612 | struct ieee80211_local *local = sdata->local; |
| 613 | struct ieee80211_hdr *hdr; |
| 614 | struct ieee80211_radiotap_header *rtap = (void *)skb->data; |
Felix Fietkau | 193e70e | 2010-01-11 06:47:00 +0100 | [diff] [blame] | 615 | u8 *p; |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 616 | |
| 617 | if (local->hw.queues < 4) |
| 618 | return 0; |
| 619 | |
| 620 | if (skb->len < 4 || |
Johannes Berg | b49bb57 | 2010-01-08 19:00:00 +0100 | [diff] [blame] | 621 | skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */) |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 622 | return 0; /* doesn't matter, frame will be dropped */ |
| 623 | |
Johannes Berg | b49bb57 | 2010-01-08 19:00:00 +0100 | [diff] [blame] | 624 | hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len)); |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 625 | |
Felix Fietkau | 861a57c | 2010-01-12 04:08:26 +0100 | [diff] [blame] | 626 | if (!ieee80211_is_data(hdr->frame_control)) { |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 627 | skb->priority = 7; |
| 628 | return ieee802_1d_to_ac[skb->priority]; |
| 629 | } |
Felix Fietkau | 861a57c | 2010-01-12 04:08:26 +0100 | [diff] [blame] | 630 | if (!ieee80211_is_data_qos(hdr->frame_control)) { |
| 631 | skb->priority = 0; |
| 632 | return ieee802_1d_to_ac[skb->priority]; |
| 633 | } |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 634 | |
Felix Fietkau | 193e70e | 2010-01-11 06:47:00 +0100 | [diff] [blame] | 635 | p = ieee80211_get_qos_ctl(hdr); |
| 636 | skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK; |
| 637 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 638 | return ieee80211_downgrade_queue(local, skb); |
| 639 | } |
| 640 | |
Johannes Berg | 587e729 | 2009-01-30 13:35:22 +0100 | [diff] [blame] | 641 | static const struct net_device_ops ieee80211_monitorif_ops = { |
| 642 | .ndo_open = ieee80211_open, |
| 643 | .ndo_stop = ieee80211_stop, |
| 644 | .ndo_uninit = ieee80211_teardown_sdata, |
| 645 | .ndo_start_xmit = ieee80211_monitor_start_xmit, |
| 646 | .ndo_set_multicast_list = ieee80211_set_multicast_list, |
| 647 | .ndo_change_mtu = ieee80211_change_mtu, |
| 648 | .ndo_set_mac_address = eth_mac_addr, |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 649 | .ndo_select_queue = ieee80211_monitor_select_queue, |
Johannes Berg | 587e729 | 2009-01-30 13:35:22 +0100 | [diff] [blame] | 650 | }; |
| 651 | |
| 652 | static void ieee80211_if_setup(struct net_device *dev) |
| 653 | { |
| 654 | ether_setup(dev); |
| 655 | dev->netdev_ops = &ieee80211_dataif_ops; |
Johannes Berg | 587e729 | 2009-01-30 13:35:22 +0100 | [diff] [blame] | 656 | dev->destructor = free_netdev; |
| 657 | } |
| 658 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 659 | static void ieee80211_iface_work(struct work_struct *work) |
| 660 | { |
| 661 | struct ieee80211_sub_if_data *sdata = |
| 662 | container_of(work, struct ieee80211_sub_if_data, work); |
| 663 | struct ieee80211_local *local = sdata->local; |
| 664 | struct sk_buff *skb; |
Johannes Berg | 344eec6 | 2010-06-10 10:21:36 +0200 | [diff] [blame] | 665 | struct sta_info *sta; |
Johannes Berg | c1475ca | 2010-06-10 10:21:37 +0200 | [diff] [blame] | 666 | struct ieee80211_ra_tid *ra_tid; |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 667 | |
| 668 | if (!ieee80211_sdata_running(sdata)) |
| 669 | return; |
| 670 | |
| 671 | if (local->scanning) |
| 672 | return; |
| 673 | |
| 674 | /* |
| 675 | * ieee80211_queue_work() should have picked up most cases, |
| 676 | * here we'll pick the rest. |
| 677 | */ |
| 678 | if (WARN(local->suspended, |
| 679 | "interface work scheduled while going to suspend\n")) |
| 680 | return; |
| 681 | |
| 682 | /* first process frames */ |
| 683 | while ((skb = skb_dequeue(&sdata->skb_queue))) { |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 684 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 685 | |
Johannes Berg | c1475ca | 2010-06-10 10:21:37 +0200 | [diff] [blame] | 686 | if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_START) { |
| 687 | ra_tid = (void *)&skb->cb; |
| 688 | ieee80211_start_tx_ba_cb(&sdata->vif, ra_tid->ra, |
| 689 | ra_tid->tid); |
| 690 | } else if (skb->pkt_type == IEEE80211_SDATA_QUEUE_AGG_STOP) { |
| 691 | ra_tid = (void *)&skb->cb; |
| 692 | ieee80211_stop_tx_ba_cb(&sdata->vif, ra_tid->ra, |
| 693 | ra_tid->tid); |
| 694 | } else if (ieee80211_is_action(mgmt->frame_control) && |
| 695 | mgmt->u.action.category == WLAN_CATEGORY_BACK) { |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 696 | int len = skb->len; |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 697 | |
Johannes Berg | a93e364 | 2010-06-10 10:21:46 +0200 | [diff] [blame] | 698 | mutex_lock(&local->sta_mtx); |
Felix Fietkau | 875ae5f | 2010-07-17 15:59:07 +0200 | [diff] [blame] | 699 | sta = sta_info_get_bss(sdata, mgmt->sa); |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 700 | if (sta) { |
| 701 | switch (mgmt->u.action.u.addba_req.action_code) { |
| 702 | case WLAN_ACTION_ADDBA_REQ: |
| 703 | ieee80211_process_addba_request( |
| 704 | local, sta, mgmt, len); |
| 705 | break; |
| 706 | case WLAN_ACTION_ADDBA_RESP: |
| 707 | ieee80211_process_addba_resp(local, sta, |
| 708 | mgmt, len); |
| 709 | break; |
| 710 | case WLAN_ACTION_DELBA: |
| 711 | ieee80211_process_delba(sdata, sta, |
| 712 | mgmt, len); |
| 713 | break; |
| 714 | default: |
| 715 | WARN_ON(1); |
| 716 | break; |
| 717 | } |
| 718 | } |
Johannes Berg | a93e364 | 2010-06-10 10:21:46 +0200 | [diff] [blame] | 719 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 344eec6 | 2010-06-10 10:21:36 +0200 | [diff] [blame] | 720 | } else if (ieee80211_is_data_qos(mgmt->frame_control)) { |
| 721 | struct ieee80211_hdr *hdr = (void *)mgmt; |
| 722 | /* |
| 723 | * So the frame isn't mgmt, but frame_control |
| 724 | * is at the right place anyway, of course, so |
| 725 | * the if statement is correct. |
| 726 | * |
| 727 | * Warn if we have other data frame types here, |
| 728 | * they must not get here. |
| 729 | */ |
| 730 | WARN_ON(hdr->frame_control & |
| 731 | cpu_to_le16(IEEE80211_STYPE_NULLFUNC)); |
| 732 | WARN_ON(!(hdr->seq_ctrl & |
| 733 | cpu_to_le16(IEEE80211_SCTL_FRAG))); |
| 734 | /* |
| 735 | * This was a fragment of a frame, received while |
| 736 | * a block-ack session was active. That cannot be |
| 737 | * right, so terminate the session. |
| 738 | */ |
Johannes Berg | a93e364 | 2010-06-10 10:21:46 +0200 | [diff] [blame] | 739 | mutex_lock(&local->sta_mtx); |
Felix Fietkau | 875ae5f | 2010-07-17 15:59:07 +0200 | [diff] [blame] | 740 | sta = sta_info_get_bss(sdata, mgmt->sa); |
Johannes Berg | 344eec6 | 2010-06-10 10:21:36 +0200 | [diff] [blame] | 741 | if (sta) { |
| 742 | u16 tid = *ieee80211_get_qos_ctl(hdr) & |
| 743 | IEEE80211_QOS_CTL_TID_MASK; |
| 744 | |
| 745 | __ieee80211_stop_rx_ba_session( |
| 746 | sta, tid, WLAN_BACK_RECIPIENT, |
| 747 | WLAN_REASON_QSTA_REQUIRE_SETUP); |
| 748 | } |
Johannes Berg | a93e364 | 2010-06-10 10:21:46 +0200 | [diff] [blame] | 749 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | bed7ee6e | 2010-06-10 10:21:35 +0200 | [diff] [blame] | 750 | } else switch (sdata->vif.type) { |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 751 | case NL80211_IFTYPE_STATION: |
| 752 | ieee80211_sta_rx_queued_mgmt(sdata, skb); |
| 753 | break; |
| 754 | case NL80211_IFTYPE_ADHOC: |
| 755 | ieee80211_ibss_rx_queued_mgmt(sdata, skb); |
| 756 | break; |
| 757 | case NL80211_IFTYPE_MESH_POINT: |
| 758 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
| 759 | break; |
| 760 | ieee80211_mesh_rx_queued_mgmt(sdata, skb); |
| 761 | break; |
| 762 | default: |
| 763 | WARN(1, "frame for unexpected interface type"); |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 764 | break; |
| 765 | } |
Johannes Berg | 36b3a62 | 2010-06-10 10:21:33 +0200 | [diff] [blame] | 766 | |
| 767 | kfree_skb(skb); |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | /* then other type-dependent work */ |
| 771 | switch (sdata->vif.type) { |
| 772 | case NL80211_IFTYPE_STATION: |
| 773 | ieee80211_sta_work(sdata); |
| 774 | break; |
| 775 | case NL80211_IFTYPE_ADHOC: |
| 776 | ieee80211_ibss_work(sdata); |
| 777 | break; |
| 778 | case NL80211_IFTYPE_MESH_POINT: |
| 779 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
| 780 | break; |
| 781 | ieee80211_mesh_work(sdata); |
| 782 | break; |
| 783 | default: |
| 784 | break; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 789 | /* |
| 790 | * Helper function to initialise an interface to a specific type. |
| 791 | */ |
| 792 | static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 793 | enum nl80211_iftype type) |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 794 | { |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 795 | /* clear type-dependent union */ |
| 796 | memset(&sdata->u, 0, sizeof(sdata->u)); |
| 797 | |
| 798 | /* and set some type-dependent values */ |
| 799 | sdata->vif.type = type; |
Johannes Berg | 587e729 | 2009-01-30 13:35:22 +0100 | [diff] [blame] | 800 | sdata->dev->netdev_ops = &ieee80211_dataif_ops; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 801 | sdata->wdev.iftype = type; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 802 | |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 803 | sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE); |
| 804 | sdata->control_port_no_encrypt = false; |
| 805 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 806 | /* only monitor differs */ |
| 807 | sdata->dev->type = ARPHRD_ETHER; |
| 808 | |
Johannes Berg | 35f20c1 | 2010-06-10 10:21:30 +0200 | [diff] [blame] | 809 | skb_queue_head_init(&sdata->skb_queue); |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 810 | INIT_WORK(&sdata->work, ieee80211_iface_work); |
Johannes Berg | 35f20c1 | 2010-06-10 10:21:30 +0200 | [diff] [blame] | 811 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 812 | switch (type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 813 | case NL80211_IFTYPE_AP: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 814 | skb_queue_head_init(&sdata->u.ap.ps_bc_buf); |
| 815 | INIT_LIST_HEAD(&sdata->u.ap.vlans); |
| 816 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 817 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 818 | ieee80211_sta_setup_sdata(sdata); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 819 | break; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 820 | case NL80211_IFTYPE_ADHOC: |
| 821 | ieee80211_ibss_setup_sdata(sdata); |
| 822 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 823 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 824 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 825 | ieee80211_mesh_init_sdata(sdata); |
| 826 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 827 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 828 | sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP; |
Johannes Berg | 587e729 | 2009-01-30 13:35:22 +0100 | [diff] [blame] | 829 | sdata->dev->netdev_ops = &ieee80211_monitorif_ops; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 830 | sdata->u.mntr_flags = MONITOR_FLAG_CONTROL | |
| 831 | MONITOR_FLAG_OTHER_BSS; |
| 832 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 833 | case NL80211_IFTYPE_WDS: |
| 834 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 835 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 836 | case NL80211_IFTYPE_UNSPECIFIED: |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 837 | case NUM_NL80211_IFTYPES: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 838 | BUG(); |
| 839 | break; |
| 840 | } |
| 841 | |
| 842 | ieee80211_debugfs_add_netdev(sdata); |
| 843 | } |
| 844 | |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 845 | int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 846 | enum nl80211_iftype type) |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 847 | { |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 848 | ASSERT_RTNL(); |
| 849 | |
| 850 | if (type == sdata->vif.type) |
| 851 | return 0; |
| 852 | |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 853 | /* Setting ad-hoc mode on non-IBSS channel is not supported. */ |
Pavel Roskin | dcebf45 | 2008-12-22 16:39:36 -0500 | [diff] [blame] | 854 | if (sdata->local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS && |
| 855 | type == NL80211_IFTYPE_ADHOC) |
Johannes Berg | e60c774 | 2008-11-26 23:31:40 +0100 | [diff] [blame] | 856 | return -EOPNOTSUPP; |
| 857 | |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 858 | /* |
| 859 | * We could, here, on changes between IBSS/STA/MESH modes, |
| 860 | * invoke an MLME function instead that disassociates etc. |
| 861 | * and goes into the requested mode. |
| 862 | */ |
| 863 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 864 | if (ieee80211_sdata_running(sdata)) |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 865 | return -EBUSY; |
| 866 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 867 | /* Purge and reset type-dependent state. */ |
| 868 | ieee80211_teardown_sdata(sdata->dev); |
| 869 | ieee80211_setup_sdata(sdata, type); |
| 870 | |
| 871 | /* reset some values that shouldn't be kept across type changes */ |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 872 | sdata->vif.bss_conf.basic_rates = |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 873 | ieee80211_mandatory_rates(sdata->local, |
| 874 | sdata->local->hw.conf.channel->band); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 875 | sdata->drop_unencrypted = 0; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 876 | if (type == NL80211_IFTYPE_STATION) |
| 877 | sdata->u.mgd.use_4addr = false; |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 878 | |
| 879 | return 0; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 880 | } |
| 881 | |
Johannes Berg | fa9029f | 2010-02-25 15:13:11 +0100 | [diff] [blame] | 882 | static void ieee80211_assign_perm_addr(struct ieee80211_local *local, |
| 883 | struct net_device *dev, |
| 884 | enum nl80211_iftype type) |
| 885 | { |
| 886 | struct ieee80211_sub_if_data *sdata; |
| 887 | u64 mask, start, addr, val, inc; |
| 888 | u8 *m; |
| 889 | u8 tmp_addr[ETH_ALEN]; |
| 890 | int i; |
| 891 | |
| 892 | /* default ... something at least */ |
| 893 | memcpy(dev->perm_addr, local->hw.wiphy->perm_addr, ETH_ALEN); |
| 894 | |
| 895 | if (is_zero_ether_addr(local->hw.wiphy->addr_mask) && |
| 896 | local->hw.wiphy->n_addresses <= 1) |
| 897 | return; |
| 898 | |
| 899 | |
| 900 | mutex_lock(&local->iflist_mtx); |
| 901 | |
| 902 | switch (type) { |
| 903 | case NL80211_IFTYPE_MONITOR: |
| 904 | /* doesn't matter */ |
| 905 | break; |
| 906 | case NL80211_IFTYPE_WDS: |
| 907 | case NL80211_IFTYPE_AP_VLAN: |
| 908 | /* match up with an AP interface */ |
| 909 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 910 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
| 911 | continue; |
| 912 | memcpy(dev->perm_addr, sdata->vif.addr, ETH_ALEN); |
| 913 | break; |
| 914 | } |
| 915 | /* keep default if no AP interface present */ |
| 916 | break; |
| 917 | default: |
| 918 | /* assign a new address if possible -- try n_addresses first */ |
| 919 | for (i = 0; i < local->hw.wiphy->n_addresses; i++) { |
| 920 | bool used = false; |
| 921 | |
| 922 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 923 | if (memcmp(local->hw.wiphy->addresses[i].addr, |
| 924 | sdata->vif.addr, ETH_ALEN) == 0) { |
| 925 | used = true; |
| 926 | break; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | if (!used) { |
| 931 | memcpy(dev->perm_addr, |
| 932 | local->hw.wiphy->addresses[i].addr, |
| 933 | ETH_ALEN); |
| 934 | break; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | /* try mask if available */ |
| 939 | if (is_zero_ether_addr(local->hw.wiphy->addr_mask)) |
| 940 | break; |
| 941 | |
| 942 | m = local->hw.wiphy->addr_mask; |
| 943 | mask = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | |
| 944 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | |
| 945 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); |
| 946 | |
| 947 | if (__ffs64(mask) + hweight64(mask) != fls64(mask)) { |
| 948 | /* not a contiguous mask ... not handled now! */ |
| 949 | printk(KERN_DEBUG "not contiguous\n"); |
| 950 | break; |
| 951 | } |
| 952 | |
| 953 | m = local->hw.wiphy->perm_addr; |
| 954 | start = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) | |
| 955 | ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | |
| 956 | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); |
| 957 | |
| 958 | inc = 1ULL<<__ffs64(mask); |
| 959 | val = (start & mask); |
| 960 | addr = (start & ~mask) | (val & mask); |
| 961 | do { |
| 962 | bool used = false; |
| 963 | |
| 964 | tmp_addr[5] = addr >> 0*8; |
| 965 | tmp_addr[4] = addr >> 1*8; |
| 966 | tmp_addr[3] = addr >> 2*8; |
| 967 | tmp_addr[2] = addr >> 3*8; |
| 968 | tmp_addr[1] = addr >> 4*8; |
| 969 | tmp_addr[0] = addr >> 5*8; |
| 970 | |
| 971 | val += inc; |
| 972 | |
| 973 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 974 | if (memcmp(tmp_addr, sdata->vif.addr, |
| 975 | ETH_ALEN) == 0) { |
| 976 | used = true; |
| 977 | break; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | if (!used) { |
| 982 | memcpy(dev->perm_addr, tmp_addr, ETH_ALEN); |
| 983 | break; |
| 984 | } |
| 985 | addr = (start & ~mask) | (val & mask); |
| 986 | } while (addr != start); |
| 987 | |
| 988 | break; |
| 989 | } |
| 990 | |
| 991 | mutex_unlock(&local->iflist_mtx); |
| 992 | } |
| 993 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 994 | int ieee80211_if_add(struct ieee80211_local *local, const char *name, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 995 | struct net_device **new_dev, enum nl80211_iftype type, |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 996 | struct vif_params *params) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 997 | { |
| 998 | struct net_device *ndev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 999 | struct ieee80211_sub_if_data *sdata = NULL; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1000 | int ret, i; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1001 | |
| 1002 | ASSERT_RTNL(); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1003 | |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 1004 | ndev = alloc_netdev_mq(sizeof(*sdata) + local->hw.vif_data_size, |
| 1005 | name, ieee80211_if_setup, local->hw.queues); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1006 | if (!ndev) |
| 1007 | return -ENOMEM; |
Johannes Berg | a272a72 | 2009-07-14 00:33:36 +0200 | [diff] [blame] | 1008 | dev_net_set(ndev, wiphy_net(local->hw.wiphy)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1009 | |
Johannes Berg | f3994ec | 2008-05-12 20:51:44 -0700 | [diff] [blame] | 1010 | ndev->needed_headroom = local->tx_headroom + |
| 1011 | 4*6 /* four MAC addresses */ |
| 1012 | + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */ |
| 1013 | + 6 /* mesh */ |
| 1014 | + 8 /* rfc1042/bridge tunnel */ |
| 1015 | - ETH_HLEN /* ethernet hard_header_len */ |
| 1016 | + IEEE80211_ENCRYPT_HEADROOM; |
| 1017 | ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM; |
| 1018 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1019 | ret = dev_alloc_name(ndev, ndev->name); |
| 1020 | if (ret < 0) |
| 1021 | goto fail; |
| 1022 | |
Johannes Berg | fa9029f | 2010-02-25 15:13:11 +0100 | [diff] [blame] | 1023 | ieee80211_assign_perm_addr(local, ndev, type); |
| 1024 | memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1025 | SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy)); |
| 1026 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1027 | /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */ |
| 1028 | sdata = netdev_priv(ndev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1029 | ndev->ieee80211_ptr = &sdata->wdev; |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1030 | memcpy(sdata->vif.addr, ndev->dev_addr, ETH_ALEN); |
| 1031 | memcpy(sdata->name, ndev->name, IFNAMSIZ); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1032 | |
| 1033 | /* initialise type-independent data */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1034 | sdata->wdev.wiphy = local->hw.wiphy; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1035 | sdata->local = local; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1036 | sdata->dev = ndev; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1037 | #ifdef CONFIG_INET |
| 1038 | sdata->arp_filter_state = true; |
| 1039 | #endif |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1040 | |
| 1041 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) |
| 1042 | skb_queue_head_init(&sdata->fragments[i].skb_list); |
| 1043 | |
| 1044 | INIT_LIST_HEAD(&sdata->key_list); |
| 1045 | |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 1046 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 1047 | struct ieee80211_supported_band *sband; |
| 1048 | sband = local->hw.wiphy->bands[i]; |
| 1049 | sdata->rc_rateidx_mask[i] = |
| 1050 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 1051 | } |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1052 | |
| 1053 | /* setup type-dependent data */ |
| 1054 | ieee80211_setup_sdata(sdata, type); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1055 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1056 | if (params) { |
| 1057 | ndev->ieee80211_ptr->use_4addr = params->use_4addr; |
| 1058 | if (type == NL80211_IFTYPE_STATION) |
| 1059 | sdata->u.mgd.use_4addr = params->use_4addr; |
| 1060 | } |
| 1061 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1062 | ret = register_netdevice(ndev); |
| 1063 | if (ret) |
| 1064 | goto fail; |
| 1065 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 1066 | if (ieee80211_vif_is_mesh(&sdata->vif) && |
| 1067 | params && params->mesh_id_len) |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 1068 | ieee80211_sdata_set_mesh_id(sdata, |
| 1069 | params->mesh_id_len, |
| 1070 | params->mesh_id); |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 1071 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 1072 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1073 | list_add_tail_rcu(&sdata->list, &local->interfaces); |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 1074 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 1075 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1076 | if (new_dev) |
| 1077 | *new_dev = ndev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1078 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1079 | return 0; |
| 1080 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1081 | fail: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1082 | free_netdev(ndev); |
| 1083 | return ret; |
| 1084 | } |
| 1085 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1086 | void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1087 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1088 | ASSERT_RTNL(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 1089 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 1090 | mutex_lock(&sdata->local->iflist_mtx); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1091 | list_del_rcu(&sdata->list); |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 1092 | mutex_unlock(&sdata->local->iflist_mtx); |
| 1093 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1094 | synchronize_rcu(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1095 | unregister_netdevice(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1098 | /* |
| 1099 | * Remove all interfaces, may only be called at hardware unregistration |
| 1100 | * time because it doesn't do RCU-safe list removals. |
| 1101 | */ |
| 1102 | void ieee80211_remove_interfaces(struct ieee80211_local *local) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1103 | { |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1104 | struct ieee80211_sub_if_data *sdata, *tmp; |
Eric Dumazet | efe117a | 2009-11-05 11:06:40 +0100 | [diff] [blame] | 1105 | LIST_HEAD(unreg_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1106 | |
| 1107 | ASSERT_RTNL(); |
| 1108 | |
Eric Dumazet | efe117a | 2009-11-05 11:06:40 +0100 | [diff] [blame] | 1109 | mutex_lock(&local->iflist_mtx); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 1110 | list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) { |
| 1111 | list_del(&sdata->list); |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 1112 | |
Eric Dumazet | efe117a | 2009-11-05 11:06:40 +0100 | [diff] [blame] | 1113 | unregister_netdevice_queue(sdata->dev, &unreg_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1114 | } |
Eric Dumazet | efe117a | 2009-11-05 11:06:40 +0100 | [diff] [blame] | 1115 | mutex_unlock(&local->iflist_mtx); |
| 1116 | unregister_netdevice_many(&unreg_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1117 | } |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1118 | |
| 1119 | static u32 ieee80211_idle_off(struct ieee80211_local *local, |
| 1120 | const char *reason) |
| 1121 | { |
| 1122 | if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE)) |
| 1123 | return 0; |
| 1124 | |
| 1125 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 1126 | wiphy_debug(local->hw.wiphy, "device no longer idle - %s\n", reason); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1127 | #endif |
| 1128 | |
| 1129 | local->hw.conf.flags &= ~IEEE80211_CONF_IDLE; |
| 1130 | return IEEE80211_CONF_CHANGE_IDLE; |
| 1131 | } |
| 1132 | |
| 1133 | static u32 ieee80211_idle_on(struct ieee80211_local *local) |
| 1134 | { |
| 1135 | if (local->hw.conf.flags & IEEE80211_CONF_IDLE) |
| 1136 | return 0; |
| 1137 | |
| 1138 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 1139 | wiphy_debug(local->hw.wiphy, "device now idle\n"); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1140 | #endif |
| 1141 | |
Johannes Berg | a80f7c0 | 2009-12-23 13:15:32 +0100 | [diff] [blame] | 1142 | drv_flush(local, false); |
| 1143 | |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1144 | local->hw.conf.flags |= IEEE80211_CONF_IDLE; |
| 1145 | return IEEE80211_CONF_CHANGE_IDLE; |
| 1146 | } |
| 1147 | |
| 1148 | u32 __ieee80211_recalc_idle(struct ieee80211_local *local) |
| 1149 | { |
| 1150 | struct ieee80211_sub_if_data *sdata; |
| 1151 | int count = 0; |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1152 | bool working = false, scanning = false; |
| 1153 | struct ieee80211_work *wk; |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1154 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1155 | #ifdef CONFIG_PROVE_LOCKING |
| 1156 | WARN_ON(debug_locks && !lockdep_rtnl_is_held() && |
| 1157 | !lockdep_is_held(&local->iflist_mtx)); |
| 1158 | #endif |
| 1159 | lockdep_assert_held(&local->mtx); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1160 | |
| 1161 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1162 | if (!ieee80211_sdata_running(sdata)) { |
| 1163 | sdata->vif.bss_conf.idle = true; |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1164 | continue; |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | sdata->old_idle = sdata->vif.bss_conf.idle; |
| 1168 | |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1169 | /* do not count disabled managed interfaces */ |
| 1170 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1171 | !sdata->u.mgd.associated) { |
| 1172 | sdata->vif.bss_conf.idle = true; |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1173 | continue; |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1174 | } |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1175 | /* do not count unused IBSS interfaces */ |
| 1176 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1177 | !sdata->u.ibss.ssid_len) { |
| 1178 | sdata->vif.bss_conf.idle = true; |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1179 | continue; |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1180 | } |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1181 | /* count everything else */ |
| 1182 | count++; |
| 1183 | } |
| 1184 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1185 | list_for_each_entry(wk, &local->work_list, list) { |
| 1186 | working = true; |
| 1187 | wk->sdata->vif.bss_conf.idle = false; |
| 1188 | } |
| 1189 | |
| 1190 | if (local->scan_sdata) { |
| 1191 | scanning = true; |
| 1192 | local->scan_sdata->vif.bss_conf.idle = false; |
| 1193 | } |
| 1194 | |
| 1195 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 1196 | if (sdata->old_idle == sdata->vif.bss_conf.idle) |
| 1197 | continue; |
| 1198 | if (!ieee80211_sdata_running(sdata)) |
| 1199 | continue; |
| 1200 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE); |
| 1201 | } |
| 1202 | |
| 1203 | if (working) |
| 1204 | return ieee80211_idle_off(local, "working"); |
| 1205 | if (scanning) |
| 1206 | return ieee80211_idle_off(local, "scanning"); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1207 | if (!count) |
| 1208 | return ieee80211_idle_on(local); |
| 1209 | else |
| 1210 | return ieee80211_idle_off(local, "in use"); |
| 1211 | |
| 1212 | return 0; |
| 1213 | } |
| 1214 | |
| 1215 | void ieee80211_recalc_idle(struct ieee80211_local *local) |
| 1216 | { |
| 1217 | u32 chg; |
| 1218 | |
| 1219 | mutex_lock(&local->iflist_mtx); |
| 1220 | chg = __ieee80211_recalc_idle(local); |
| 1221 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 58905ca | 2009-05-07 14:23:01 +0200 | [diff] [blame] | 1222 | if (chg) |
| 1223 | ieee80211_hw_config(local, chg); |
Johannes Berg | 5cff20e | 2009-04-29 12:26:17 +0200 | [diff] [blame] | 1224 | } |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1225 | |
| 1226 | static int netdev_notify(struct notifier_block *nb, |
| 1227 | unsigned long state, |
| 1228 | void *ndev) |
| 1229 | { |
| 1230 | struct net_device *dev = ndev; |
| 1231 | struct ieee80211_sub_if_data *sdata; |
| 1232 | |
| 1233 | if (state != NETDEV_CHANGENAME) |
| 1234 | return 0; |
| 1235 | |
| 1236 | if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy) |
| 1237 | return 0; |
| 1238 | |
| 1239 | if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid) |
| 1240 | return 0; |
| 1241 | |
| 1242 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1243 | |
Johannes Berg | 2f5265e | 2010-02-12 10:45:05 +0100 | [diff] [blame] | 1244 | memcpy(sdata->name, dev->name, IFNAMSIZ); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1245 | |
| 1246 | ieee80211_debugfs_rename_netdev(sdata); |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
| 1250 | static struct notifier_block mac80211_netdev_notifier = { |
| 1251 | .notifier_call = netdev_notify, |
| 1252 | }; |
| 1253 | |
| 1254 | int ieee80211_iface_init(void) |
| 1255 | { |
| 1256 | return register_netdevice_notifier(&mac80211_netdev_notifier); |
| 1257 | } |
| 1258 | |
| 1259 | void ieee80211_iface_exit(void) |
| 1260 | { |
| 1261 | unregister_netdevice_notifier(&mac80211_netdev_notifier); |
| 1262 | } |