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 | */ |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/if_arp.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/rtnetlink.h> |
| 17 | #include <net/mac80211.h> |
| 18 | #include "ieee80211_i.h" |
| 19 | #include "sta_info.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 20 | #include "debugfs_netdev.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 21 | #include "mesh.h" |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 22 | #include "led.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 23 | |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 24 | static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) |
| 25 | { |
| 26 | int meshhdrlen; |
| 27 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 28 | |
| 29 | meshhdrlen = (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) ? 5 : 0; |
| 30 | |
| 31 | /* FIX: what would be proper limits for MTU? |
| 32 | * This interface uses 802.3 frames. */ |
| 33 | if (new_mtu < 256 || |
| 34 | new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) { |
| 35 | return -EINVAL; |
| 36 | } |
| 37 | |
| 38 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 39 | printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu); |
| 40 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 41 | dev->mtu = new_mtu; |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static inline int identical_mac_addr_allowed(int type1, int type2) |
| 46 | { |
| 47 | return type1 == NL80211_IFTYPE_MONITOR || |
| 48 | type2 == NL80211_IFTYPE_MONITOR || |
| 49 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) || |
| 50 | (type1 == NL80211_IFTYPE_WDS && |
| 51 | (type2 == NL80211_IFTYPE_WDS || |
| 52 | type2 == NL80211_IFTYPE_AP)) || |
| 53 | (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) || |
| 54 | (type1 == NL80211_IFTYPE_AP_VLAN && |
| 55 | (type2 == NL80211_IFTYPE_AP || |
| 56 | type2 == NL80211_IFTYPE_AP_VLAN)); |
| 57 | } |
| 58 | |
| 59 | static int ieee80211_open(struct net_device *dev) |
| 60 | { |
| 61 | struct ieee80211_sub_if_data *sdata, *nsdata; |
| 62 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 63 | struct sta_info *sta; |
| 64 | struct ieee80211_if_init_conf conf; |
| 65 | u32 changed = 0; |
| 66 | int res; |
| 67 | bool need_hw_reconfig = 0; |
| 68 | u8 null_addr[ETH_ALEN] = {0}; |
| 69 | |
| 70 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 71 | |
| 72 | /* fail early if user set an invalid address */ |
| 73 | if (compare_ether_addr(dev->dev_addr, null_addr) && |
| 74 | !is_valid_ether_addr(dev->dev_addr)) |
| 75 | return -EADDRNOTAVAIL; |
| 76 | |
| 77 | /* we hold the RTNL here so can safely walk the list */ |
| 78 | list_for_each_entry(nsdata, &local->interfaces, list) { |
| 79 | struct net_device *ndev = nsdata->dev; |
| 80 | |
| 81 | if (ndev != dev && netif_running(ndev)) { |
| 82 | /* |
| 83 | * Allow only a single IBSS interface to be up at any |
| 84 | * time. This is restricted because beacon distribution |
| 85 | * cannot work properly if both are in the same IBSS. |
| 86 | * |
| 87 | * To remove this restriction we'd have to disallow them |
| 88 | * from setting the same SSID on different IBSS interfaces |
| 89 | * belonging to the same hardware. Then, however, we're |
| 90 | * faced with having to adopt two different TSF timers... |
| 91 | */ |
| 92 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
| 93 | nsdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 94 | return -EBUSY; |
| 95 | |
| 96 | /* |
| 97 | * The remaining checks are only performed for interfaces |
| 98 | * with the same MAC address. |
| 99 | */ |
| 100 | if (compare_ether_addr(dev->dev_addr, ndev->dev_addr)) |
| 101 | continue; |
| 102 | |
| 103 | /* |
| 104 | * check whether it may have the same address |
| 105 | */ |
| 106 | if (!identical_mac_addr_allowed(sdata->vif.type, |
| 107 | nsdata->vif.type)) |
| 108 | return -ENOTUNIQ; |
| 109 | |
| 110 | /* |
| 111 | * can only add VLANs to enabled APs |
| 112 | */ |
| 113 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
| 114 | nsdata->vif.type == NL80211_IFTYPE_AP) |
| 115 | sdata->bss = &nsdata->u.ap; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | switch (sdata->vif.type) { |
| 120 | case NL80211_IFTYPE_WDS: |
| 121 | if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) |
| 122 | return -ENOLINK; |
| 123 | break; |
| 124 | case NL80211_IFTYPE_AP_VLAN: |
| 125 | if (!sdata->bss) |
| 126 | return -ENOLINK; |
| 127 | list_add(&sdata->u.vlan.list, &sdata->bss->vlans); |
| 128 | break; |
| 129 | case NL80211_IFTYPE_AP: |
| 130 | sdata->bss = &sdata->u.ap; |
| 131 | break; |
| 132 | case NL80211_IFTYPE_MESH_POINT: |
| 133 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
| 134 | break; |
| 135 | /* mesh ifaces must set allmulti to forward mcast traffic */ |
| 136 | atomic_inc(&local->iff_allmultis); |
| 137 | break; |
| 138 | case NL80211_IFTYPE_STATION: |
| 139 | case NL80211_IFTYPE_MONITOR: |
| 140 | case NL80211_IFTYPE_ADHOC: |
| 141 | /* no special treatment */ |
| 142 | break; |
| 143 | case NL80211_IFTYPE_UNSPECIFIED: |
| 144 | case __NL80211_IFTYPE_AFTER_LAST: |
| 145 | /* cannot happen */ |
| 146 | WARN_ON(1); |
| 147 | break; |
| 148 | } |
| 149 | |
| 150 | if (local->open_count == 0) { |
| 151 | res = 0; |
| 152 | if (local->ops->start) |
| 153 | res = local->ops->start(local_to_hw(local)); |
| 154 | if (res) |
| 155 | goto err_del_bss; |
| 156 | need_hw_reconfig = 1; |
| 157 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * Check all interfaces and copy the hopefully now-present |
| 162 | * MAC address to those that have the special null one. |
| 163 | */ |
| 164 | list_for_each_entry(nsdata, &local->interfaces, list) { |
| 165 | struct net_device *ndev = nsdata->dev; |
| 166 | |
| 167 | /* |
| 168 | * No need to check netif_running since we do not allow |
| 169 | * it to start up with this invalid address. |
| 170 | */ |
| 171 | if (compare_ether_addr(null_addr, ndev->dev_addr) == 0) |
| 172 | memcpy(ndev->dev_addr, |
| 173 | local->hw.wiphy->perm_addr, |
| 174 | ETH_ALEN); |
| 175 | } |
| 176 | |
| 177 | if (compare_ether_addr(null_addr, local->mdev->dev_addr) == 0) |
| 178 | memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, |
| 179 | ETH_ALEN); |
| 180 | |
| 181 | /* |
| 182 | * Validate the MAC address for this device. |
| 183 | */ |
| 184 | if (!is_valid_ether_addr(dev->dev_addr)) { |
| 185 | if (!local->open_count && local->ops->stop) |
| 186 | local->ops->stop(local_to_hw(local)); |
| 187 | return -EADDRNOTAVAIL; |
| 188 | } |
| 189 | |
| 190 | switch (sdata->vif.type) { |
| 191 | case NL80211_IFTYPE_AP_VLAN: |
| 192 | /* no need to tell driver */ |
| 193 | break; |
| 194 | case NL80211_IFTYPE_MONITOR: |
| 195 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
| 196 | local->cooked_mntrs++; |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | /* must be before the call to ieee80211_configure_filter */ |
| 201 | local->monitors++; |
| 202 | if (local->monitors == 1) |
| 203 | local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; |
| 204 | |
| 205 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) |
| 206 | local->fif_fcsfail++; |
| 207 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) |
| 208 | local->fif_plcpfail++; |
| 209 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) |
| 210 | local->fif_control++; |
| 211 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) |
| 212 | local->fif_other_bss++; |
| 213 | |
| 214 | netif_addr_lock_bh(local->mdev); |
| 215 | ieee80211_configure_filter(local); |
| 216 | netif_addr_unlock_bh(local->mdev); |
| 217 | break; |
| 218 | case NL80211_IFTYPE_STATION: |
| 219 | case NL80211_IFTYPE_ADHOC: |
| 220 | sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
| 221 | /* fall through */ |
| 222 | default: |
| 223 | conf.vif = &sdata->vif; |
| 224 | conf.type = sdata->vif.type; |
| 225 | conf.mac_addr = dev->dev_addr; |
| 226 | res = local->ops->add_interface(local_to_hw(local), &conf); |
| 227 | if (res) |
| 228 | goto err_stop; |
| 229 | |
| 230 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 231 | ieee80211_start_mesh(sdata); |
| 232 | changed |= ieee80211_reset_erp_info(sdata); |
| 233 | ieee80211_bss_info_change_notify(sdata, changed); |
| 234 | ieee80211_enable_keys(sdata); |
| 235 | |
| 236 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 237 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) |
| 238 | netif_carrier_off(dev); |
| 239 | else |
| 240 | netif_carrier_on(dev); |
| 241 | } |
| 242 | |
| 243 | if (sdata->vif.type == NL80211_IFTYPE_WDS) { |
| 244 | /* Create STA entry for the WDS peer */ |
| 245 | sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, |
| 246 | GFP_KERNEL); |
| 247 | if (!sta) { |
| 248 | res = -ENOMEM; |
| 249 | goto err_del_interface; |
| 250 | } |
| 251 | |
| 252 | /* no locking required since STA is not live yet */ |
| 253 | sta->flags |= WLAN_STA_AUTHORIZED; |
| 254 | |
| 255 | res = sta_info_insert(sta); |
| 256 | if (res) { |
| 257 | /* STA has been freed */ |
| 258 | goto err_del_interface; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | if (local->open_count == 0) { |
| 263 | res = dev_open(local->mdev); |
| 264 | WARN_ON(res); |
| 265 | if (res) |
| 266 | goto err_del_interface; |
| 267 | tasklet_enable(&local->tx_pending_tasklet); |
| 268 | tasklet_enable(&local->tasklet); |
| 269 | } |
| 270 | |
| 271 | /* |
| 272 | * set_multicast_list will be invoked by the networking core |
| 273 | * which will check whether any increments here were done in |
| 274 | * error and sync them down to the hardware as filter flags. |
| 275 | */ |
| 276 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) |
| 277 | atomic_inc(&local->iff_allmultis); |
| 278 | |
| 279 | if (sdata->flags & IEEE80211_SDATA_PROMISC) |
| 280 | atomic_inc(&local->iff_promiscs); |
| 281 | |
| 282 | local->open_count++; |
| 283 | if (need_hw_reconfig) { |
| 284 | ieee80211_hw_config(local); |
| 285 | /* |
| 286 | * set default queue parameters so drivers don't |
| 287 | * need to initialise the hardware if the hardware |
| 288 | * doesn't start up with sane defaults |
| 289 | */ |
| 290 | ieee80211_set_wmm_default(sdata); |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * ieee80211_sta_work is disabled while network interface |
| 295 | * is down. Therefore, some configuration changes may not |
| 296 | * yet be effective. Trigger execution of ieee80211_sta_work |
| 297 | * to fix this. |
| 298 | */ |
| 299 | if (sdata->vif.type == NL80211_IFTYPE_STATION || |
| 300 | sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
| 301 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 302 | queue_work(local->hw.workqueue, &ifsta->work); |
| 303 | } |
| 304 | |
| 305 | netif_tx_start_all_queues(dev); |
| 306 | |
| 307 | return 0; |
| 308 | err_del_interface: |
| 309 | local->ops->remove_interface(local_to_hw(local), &conf); |
| 310 | err_stop: |
| 311 | if (!local->open_count && local->ops->stop) |
| 312 | local->ops->stop(local_to_hw(local)); |
| 313 | err_del_bss: |
| 314 | sdata->bss = NULL; |
| 315 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 316 | list_del(&sdata->u.vlan.list); |
| 317 | return res; |
| 318 | } |
| 319 | |
| 320 | static int ieee80211_stop(struct net_device *dev) |
| 321 | { |
| 322 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 323 | struct ieee80211_local *local = sdata->local; |
| 324 | struct ieee80211_if_init_conf conf; |
| 325 | struct sta_info *sta; |
| 326 | |
| 327 | /* |
| 328 | * Stop TX on this interface first. |
| 329 | */ |
| 330 | netif_tx_stop_all_queues(dev); |
| 331 | |
| 332 | /* |
| 333 | * Now delete all active aggregation sessions. |
| 334 | */ |
| 335 | rcu_read_lock(); |
| 336 | |
| 337 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 338 | if (sta->sdata == sdata) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame^] | 339 | ieee80211_sta_tear_down_BA_sessions(sdata, |
| 340 | sta->sta.addr); |
Johannes Berg | 0d143fe | 2008-09-11 00:01:59 +0200 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | rcu_read_unlock(); |
| 344 | |
| 345 | /* |
| 346 | * Remove all stations associated with this interface. |
| 347 | * |
| 348 | * This must be done before calling ops->remove_interface() |
| 349 | * because otherwise we can later invoke ops->sta_notify() |
| 350 | * whenever the STAs are removed, and that invalidates driver |
| 351 | * assumptions about always getting a vif pointer that is valid |
| 352 | * (because if we remove a STA after ops->remove_interface() |
| 353 | * the driver will have removed the vif info already!) |
| 354 | * |
| 355 | * We could relax this and only unlink the stations from the |
| 356 | * hash table and list but keep them on a per-sdata list that |
| 357 | * will be inserted back again when the interface is brought |
| 358 | * up again, but I don't currently see a use case for that, |
| 359 | * except with WDS which gets a STA entry created when it is |
| 360 | * brought up. |
| 361 | */ |
| 362 | sta_info_flush(local, sdata); |
| 363 | |
| 364 | /* |
| 365 | * Don't count this interface for promisc/allmulti while it |
| 366 | * is down. dev_mc_unsync() will invoke set_multicast_list |
| 367 | * on the master interface which will sync these down to the |
| 368 | * hardware as filter flags. |
| 369 | */ |
| 370 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) |
| 371 | atomic_dec(&local->iff_allmultis); |
| 372 | |
| 373 | if (sdata->flags & IEEE80211_SDATA_PROMISC) |
| 374 | atomic_dec(&local->iff_promiscs); |
| 375 | |
| 376 | dev_mc_unsync(local->mdev, dev); |
| 377 | |
| 378 | /* APs need special treatment */ |
| 379 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 380 | struct ieee80211_sub_if_data *vlan, *tmp; |
| 381 | struct beacon_data *old_beacon = sdata->u.ap.beacon; |
| 382 | |
| 383 | /* remove beacon */ |
| 384 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 385 | synchronize_rcu(); |
| 386 | kfree(old_beacon); |
| 387 | |
| 388 | /* down all dependent devices, that is VLANs */ |
| 389 | list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans, |
| 390 | u.vlan.list) |
| 391 | dev_close(vlan->dev); |
| 392 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); |
| 393 | } |
| 394 | |
| 395 | local->open_count--; |
| 396 | |
| 397 | switch (sdata->vif.type) { |
| 398 | case NL80211_IFTYPE_AP_VLAN: |
| 399 | list_del(&sdata->u.vlan.list); |
| 400 | /* no need to tell driver */ |
| 401 | break; |
| 402 | case NL80211_IFTYPE_MONITOR: |
| 403 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
| 404 | local->cooked_mntrs--; |
| 405 | break; |
| 406 | } |
| 407 | |
| 408 | local->monitors--; |
| 409 | if (local->monitors == 0) |
| 410 | local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; |
| 411 | |
| 412 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) |
| 413 | local->fif_fcsfail--; |
| 414 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) |
| 415 | local->fif_plcpfail--; |
| 416 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) |
| 417 | local->fif_control--; |
| 418 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) |
| 419 | local->fif_other_bss--; |
| 420 | |
| 421 | netif_addr_lock_bh(local->mdev); |
| 422 | ieee80211_configure_filter(local); |
| 423 | netif_addr_unlock_bh(local->mdev); |
| 424 | break; |
| 425 | case NL80211_IFTYPE_STATION: |
| 426 | case NL80211_IFTYPE_ADHOC: |
| 427 | sdata->u.sta.state = IEEE80211_STA_MLME_DISABLED; |
| 428 | memset(sdata->u.sta.bssid, 0, ETH_ALEN); |
| 429 | del_timer_sync(&sdata->u.sta.timer); |
| 430 | /* |
| 431 | * If the timer fired while we waited for it, it will have |
| 432 | * requeued the work. Now the work will be running again |
| 433 | * but will not rearm the timer again because it checks |
| 434 | * whether the interface is running, which, at this point, |
| 435 | * it no longer is. |
| 436 | */ |
| 437 | cancel_work_sync(&sdata->u.sta.work); |
| 438 | /* |
| 439 | * When we get here, the interface is marked down. |
| 440 | * Call synchronize_rcu() to wait for the RX path |
| 441 | * should it be using the interface and enqueuing |
| 442 | * frames at this very time on another CPU. |
| 443 | */ |
| 444 | synchronize_rcu(); |
| 445 | skb_queue_purge(&sdata->u.sta.skb_queue); |
| 446 | |
| 447 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; |
| 448 | kfree(sdata->u.sta.extra_ie); |
| 449 | sdata->u.sta.extra_ie = NULL; |
| 450 | sdata->u.sta.extra_ie_len = 0; |
| 451 | /* fall through */ |
| 452 | case NL80211_IFTYPE_MESH_POINT: |
| 453 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
| 454 | /* allmulti is always set on mesh ifaces */ |
| 455 | atomic_dec(&local->iff_allmultis); |
| 456 | ieee80211_stop_mesh(sdata); |
| 457 | } |
| 458 | /* fall through */ |
| 459 | default: |
| 460 | if (local->scan_sdata == sdata) { |
| 461 | if (!local->ops->hw_scan) |
| 462 | cancel_delayed_work_sync(&local->scan_work); |
| 463 | /* |
| 464 | * The software scan can no longer run now, so we can |
| 465 | * clear out the scan_sdata reference. However, the |
| 466 | * hardware scan may still be running. The complete |
| 467 | * function must be prepared to handle a NULL value. |
| 468 | */ |
| 469 | local->scan_sdata = NULL; |
| 470 | /* |
| 471 | * The memory barrier guarantees that another CPU |
| 472 | * that is hardware-scanning will now see the fact |
| 473 | * that this interface is gone. |
| 474 | */ |
| 475 | smp_mb(); |
| 476 | /* |
| 477 | * If software scanning, complete the scan but since |
| 478 | * the scan_sdata is NULL already don't send out a |
| 479 | * scan event to userspace -- the scan is incomplete. |
| 480 | */ |
| 481 | if (local->sw_scanning) |
| 482 | ieee80211_scan_completed(&local->hw); |
| 483 | } |
| 484 | |
| 485 | conf.vif = &sdata->vif; |
| 486 | conf.type = sdata->vif.type; |
| 487 | conf.mac_addr = dev->dev_addr; |
| 488 | /* disable all keys for as long as this netdev is down */ |
| 489 | ieee80211_disable_keys(sdata); |
| 490 | local->ops->remove_interface(local_to_hw(local), &conf); |
| 491 | } |
| 492 | |
| 493 | sdata->bss = NULL; |
| 494 | |
| 495 | if (local->open_count == 0) { |
| 496 | if (netif_running(local->mdev)) |
| 497 | dev_close(local->mdev); |
| 498 | |
| 499 | if (local->ops->stop) |
| 500 | local->ops->stop(local_to_hw(local)); |
| 501 | |
| 502 | ieee80211_led_radio(local, 0); |
| 503 | |
| 504 | flush_workqueue(local->hw.workqueue); |
| 505 | |
| 506 | tasklet_disable(&local->tx_pending_tasklet); |
| 507 | tasklet_disable(&local->tasklet); |
| 508 | } |
| 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | static void ieee80211_set_multicast_list(struct net_device *dev) |
| 514 | { |
| 515 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 516 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 517 | int allmulti, promisc, sdata_allmulti, sdata_promisc; |
| 518 | |
| 519 | allmulti = !!(dev->flags & IFF_ALLMULTI); |
| 520 | promisc = !!(dev->flags & IFF_PROMISC); |
| 521 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); |
| 522 | sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC); |
| 523 | |
| 524 | if (allmulti != sdata_allmulti) { |
| 525 | if (dev->flags & IFF_ALLMULTI) |
| 526 | atomic_inc(&local->iff_allmultis); |
| 527 | else |
| 528 | atomic_dec(&local->iff_allmultis); |
| 529 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; |
| 530 | } |
| 531 | |
| 532 | if (promisc != sdata_promisc) { |
| 533 | if (dev->flags & IFF_PROMISC) |
| 534 | atomic_inc(&local->iff_promiscs); |
| 535 | else |
| 536 | atomic_dec(&local->iff_promiscs); |
| 537 | sdata->flags ^= IEEE80211_SDATA_PROMISC; |
| 538 | } |
| 539 | |
| 540 | dev_mc_sync(local->mdev, dev); |
| 541 | } |
| 542 | |
| 543 | static void ieee80211_if_setup(struct net_device *dev) |
| 544 | { |
| 545 | ether_setup(dev); |
| 546 | dev->hard_start_xmit = ieee80211_subif_start_xmit; |
| 547 | dev->wireless_handlers = &ieee80211_iw_handler_def; |
| 548 | dev->set_multicast_list = ieee80211_set_multicast_list; |
| 549 | dev->change_mtu = ieee80211_change_mtu; |
| 550 | dev->open = ieee80211_open; |
| 551 | dev->stop = ieee80211_stop; |
| 552 | dev->destructor = free_netdev; |
| 553 | /* we will validate the address ourselves in ->open */ |
| 554 | dev->validate_addr = NULL; |
| 555 | } |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 556 | /* |
| 557 | * Called when the netdev is removed or, by the code below, before |
| 558 | * the interface type changes. |
| 559 | */ |
| 560 | static void ieee80211_teardown_sdata(struct net_device *dev) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 561 | { |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 562 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 563 | struct ieee80211_local *local = sdata->local; |
| 564 | struct beacon_data *beacon; |
| 565 | struct sk_buff *skb; |
| 566 | int flushed; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 567 | int i; |
| 568 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 569 | /* free extra data */ |
| 570 | ieee80211_free_keys(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 571 | |
Jouni Malinen | aee14ce | 2008-09-09 16:33:15 +0200 | [diff] [blame] | 572 | ieee80211_debugfs_remove_netdev(sdata); |
| 573 | |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 574 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 575 | __skb_queue_purge(&sdata->fragments[i].skb_list); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 576 | sdata->fragment_next = 0; |
| 577 | |
| 578 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 579 | case NL80211_IFTYPE_AP: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 580 | beacon = sdata->u.ap.beacon; |
| 581 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 582 | synchronize_rcu(); |
| 583 | kfree(beacon); |
| 584 | |
| 585 | while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) { |
| 586 | local->total_ps_buffered--; |
| 587 | dev_kfree_skb(skb); |
| 588 | } |
| 589 | |
| 590 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 591 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 592 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 593 | mesh_rmc_free(sdata); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 594 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 595 | case NL80211_IFTYPE_STATION: |
| 596 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 597 | kfree(sdata->u.sta.extra_ie); |
| 598 | kfree(sdata->u.sta.assocreq_ies); |
| 599 | kfree(sdata->u.sta.assocresp_ies); |
| 600 | kfree_skb(sdata->u.sta.probe_resp); |
| 601 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 602 | case NL80211_IFTYPE_WDS: |
| 603 | case NL80211_IFTYPE_AP_VLAN: |
| 604 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 605 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 606 | case NL80211_IFTYPE_UNSPECIFIED: |
| 607 | case __NL80211_IFTYPE_AFTER_LAST: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 608 | BUG(); |
| 609 | break; |
| 610 | } |
| 611 | |
| 612 | flushed = sta_info_flush(local, sdata); |
| 613 | WARN_ON(flushed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 616 | /* |
| 617 | * Helper function to initialise an interface to a specific type. |
| 618 | */ |
| 619 | static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 620 | enum nl80211_iftype type) |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 621 | { |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 622 | /* clear type-dependent union */ |
| 623 | memset(&sdata->u, 0, sizeof(sdata->u)); |
| 624 | |
| 625 | /* and set some type-dependent values */ |
| 626 | sdata->vif.type = type; |
| 627 | |
| 628 | /* only monitor differs */ |
| 629 | sdata->dev->type = ARPHRD_ETHER; |
| 630 | |
| 631 | switch (type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 632 | case NL80211_IFTYPE_AP: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 633 | skb_queue_head_init(&sdata->u.ap.ps_bc_buf); |
| 634 | INIT_LIST_HEAD(&sdata->u.ap.vlans); |
| 635 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 636 | case NL80211_IFTYPE_STATION: |
| 637 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 638 | ieee80211_sta_setup_sdata(sdata); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 639 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 640 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 641 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 642 | ieee80211_mesh_init_sdata(sdata); |
| 643 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 644 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 645 | sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 646 | sdata->dev->hard_start_xmit = ieee80211_monitor_start_xmit; |
| 647 | sdata->u.mntr_flags = MONITOR_FLAG_CONTROL | |
| 648 | MONITOR_FLAG_OTHER_BSS; |
| 649 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 650 | case NL80211_IFTYPE_WDS: |
| 651 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 652 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 653 | case NL80211_IFTYPE_UNSPECIFIED: |
| 654 | case __NL80211_IFTYPE_AFTER_LAST: |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 655 | BUG(); |
| 656 | break; |
| 657 | } |
| 658 | |
| 659 | ieee80211_debugfs_add_netdev(sdata); |
| 660 | } |
| 661 | |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 662 | int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 663 | enum nl80211_iftype type) |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 664 | { |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 665 | ASSERT_RTNL(); |
| 666 | |
| 667 | if (type == sdata->vif.type) |
| 668 | return 0; |
| 669 | |
| 670 | /* |
| 671 | * We could, here, on changes between IBSS/STA/MESH modes, |
| 672 | * invoke an MLME function instead that disassociates etc. |
| 673 | * and goes into the requested mode. |
| 674 | */ |
| 675 | |
| 676 | if (netif_running(sdata->dev)) |
| 677 | return -EBUSY; |
| 678 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 679 | /* Purge and reset type-dependent state. */ |
| 680 | ieee80211_teardown_sdata(sdata->dev); |
| 681 | ieee80211_setup_sdata(sdata, type); |
| 682 | |
| 683 | /* reset some values that shouldn't be kept across type changes */ |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 684 | sdata->bss_conf.basic_rates = |
| 685 | ieee80211_mandatory_rates(sdata->local, |
| 686 | sdata->local->hw.conf.channel->band); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 687 | sdata->drop_unencrypted = 0; |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 688 | |
| 689 | return 0; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 690 | } |
| 691 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 692 | int ieee80211_if_add(struct ieee80211_local *local, const char *name, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 693 | struct net_device **new_dev, enum nl80211_iftype type, |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 694 | struct vif_params *params) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 695 | { |
| 696 | struct net_device *ndev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 697 | struct ieee80211_sub_if_data *sdata = NULL; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 698 | int ret, i; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 699 | |
| 700 | ASSERT_RTNL(); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 701 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 702 | ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 703 | name, ieee80211_if_setup); |
| 704 | if (!ndev) |
| 705 | return -ENOMEM; |
| 706 | |
Johannes Berg | f3994ec | 2008-05-12 20:51:44 -0700 | [diff] [blame] | 707 | ndev->needed_headroom = local->tx_headroom + |
| 708 | 4*6 /* four MAC addresses */ |
| 709 | + 2 + 2 + 2 + 2 /* ctl, dur, seq, qos */ |
| 710 | + 6 /* mesh */ |
| 711 | + 8 /* rfc1042/bridge tunnel */ |
| 712 | - ETH_HLEN /* ethernet hard_header_len */ |
| 713 | + IEEE80211_ENCRYPT_HEADROOM; |
| 714 | ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM; |
| 715 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 716 | ret = dev_alloc_name(ndev, ndev->name); |
| 717 | if (ret < 0) |
| 718 | goto fail; |
| 719 | |
| 720 | memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 721 | SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy)); |
| 722 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 723 | /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */ |
| 724 | sdata = netdev_priv(ndev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 725 | ndev->ieee80211_ptr = &sdata->wdev; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 726 | |
| 727 | /* initialise type-independent data */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 728 | sdata->wdev.wiphy = local->hw.wiphy; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 729 | sdata->local = local; |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 730 | sdata->dev = ndev; |
| 731 | |
| 732 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) |
| 733 | skb_queue_head_init(&sdata->fragments[i].skb_list); |
| 734 | |
| 735 | INIT_LIST_HEAD(&sdata->key_list); |
| 736 | |
| 737 | sdata->force_unicast_rateidx = -1; |
| 738 | sdata->max_ratectrl_rateidx = -1; |
| 739 | |
| 740 | /* setup type-dependent data */ |
| 741 | ieee80211_setup_sdata(sdata, type); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 742 | |
| 743 | ret = register_netdevice(ndev); |
| 744 | if (ret) |
| 745 | goto fail; |
| 746 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 747 | ndev->uninit = ieee80211_teardown_sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 748 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 749 | if (ieee80211_vif_is_mesh(&sdata->vif) && |
| 750 | params && params->mesh_id_len) |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 751 | ieee80211_sdata_set_mesh_id(sdata, |
| 752 | params->mesh_id_len, |
| 753 | params->mesh_id); |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 754 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 755 | list_add_tail_rcu(&sdata->list, &local->interfaces); |
| 756 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 757 | if (new_dev) |
| 758 | *new_dev = ndev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 759 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 760 | return 0; |
| 761 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 762 | fail: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 763 | free_netdev(ndev); |
| 764 | return ret; |
| 765 | } |
| 766 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 767 | void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 768 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 769 | ASSERT_RTNL(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 770 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 771 | list_del_rcu(&sdata->list); |
| 772 | synchronize_rcu(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 773 | unregister_netdevice(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 776 | /* |
| 777 | * Remove all interfaces, may only be called at hardware unregistration |
| 778 | * time because it doesn't do RCU-safe list removals. |
| 779 | */ |
| 780 | void ieee80211_remove_interfaces(struct ieee80211_local *local) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 781 | { |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 782 | struct ieee80211_sub_if_data *sdata, *tmp; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 783 | |
| 784 | ASSERT_RTNL(); |
| 785 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 786 | list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) { |
| 787 | list_del(&sdata->list); |
| 788 | unregister_netdevice(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 789 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 790 | } |