Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/if_arp.h> |
| 12 | #include <linux/netdevice.h> |
| 13 | #include <linux/rtnetlink.h> |
| 14 | #include <net/mac80211.h> |
| 15 | #include "ieee80211_i.h" |
| 16 | #include "sta_info.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 17 | #include "debugfs_netdev.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame^] | 18 | #ifdef CONFIG_MAC80211_MESH |
| 19 | #include "mesh.h" |
| 20 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 21 | |
| 22 | void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata) |
| 23 | { |
| 24 | int i; |
| 25 | |
| 26 | /* Default values for sub-interface parameters */ |
| 27 | sdata->drop_unencrypted = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) |
| 29 | skb_queue_head_init(&sdata->fragments[i].skb_list); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 30 | |
| 31 | INIT_LIST_HEAD(&sdata->key_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data *sdata) |
| 35 | { |
| 36 | int i; |
| 37 | |
| 38 | for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) { |
| 39 | __skb_queue_purge(&sdata->fragments[i].skb_list); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /* Must be called with rtnl lock held. */ |
| 44 | int ieee80211_if_add(struct net_device *dev, const char *name, |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame^] | 45 | struct net_device **new_dev, int type, |
| 46 | struct vif_params *params) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 47 | { |
| 48 | struct net_device *ndev; |
| 49 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 50 | struct ieee80211_sub_if_data *sdata = NULL; |
| 51 | int ret; |
| 52 | |
| 53 | ASSERT_RTNL(); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 54 | ndev = alloc_netdev(sizeof(*sdata) + local->hw.vif_data_size, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 55 | name, ieee80211_if_setup); |
| 56 | if (!ndev) |
| 57 | return -ENOMEM; |
| 58 | |
| 59 | ret = dev_alloc_name(ndev, ndev->name); |
| 60 | if (ret < 0) |
| 61 | goto fail; |
| 62 | |
| 63 | memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN); |
| 64 | ndev->base_addr = dev->base_addr; |
| 65 | ndev->irq = dev->irq; |
| 66 | ndev->mem_start = dev->mem_start; |
| 67 | ndev->mem_end = dev->mem_end; |
| 68 | SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy)); |
| 69 | |
| 70 | sdata = IEEE80211_DEV_TO_SUB_IF(ndev); |
| 71 | ndev->ieee80211_ptr = &sdata->wdev; |
| 72 | sdata->wdev.wiphy = local->hw.wiphy; |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 73 | sdata->vif.type = IEEE80211_IF_TYPE_AP; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 74 | sdata->dev = ndev; |
| 75 | sdata->local = local; |
| 76 | ieee80211_if_sdata_init(sdata); |
| 77 | |
| 78 | ret = register_netdevice(ndev); |
| 79 | if (ret) |
| 80 | goto fail; |
| 81 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 82 | ieee80211_debugfs_add_netdev(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 83 | ieee80211_if_set_type(ndev, type); |
| 84 | |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame^] | 85 | #ifdef CONFIG_MAC80211_MESH |
| 86 | if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT && |
| 87 | params && params->mesh_id_len) { |
| 88 | sdata->u.sta.mesh_id_len = params->mesh_id_len; |
| 89 | memcpy(sdata->u.sta.mesh_id, params->mesh_id, |
| 90 | params->mesh_id_len); |
| 91 | } |
| 92 | #endif |
| 93 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 94 | /* we're under RTNL so all this is fine */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 95 | if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 96 | __ieee80211_if_del(local, sdata); |
| 97 | return -ENODEV; |
| 98 | } |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 99 | list_add_tail_rcu(&sdata->list, &local->interfaces); |
| 100 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 101 | if (new_dev) |
| 102 | *new_dev = ndev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 103 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 104 | return 0; |
| 105 | |
| 106 | fail: |
| 107 | free_netdev(ndev); |
| 108 | return ret; |
| 109 | } |
| 110 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 111 | void ieee80211_if_set_type(struct net_device *dev, int type) |
| 112 | { |
| 113 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 114 | int oldtype = sdata->vif.type; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 115 | |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 116 | /* |
| 117 | * We need to call this function on the master interface |
| 118 | * which already has a hard_start_xmit routine assigned |
| 119 | * which must not be changed. |
| 120 | */ |
John W. Linville | 0654ff0 | 2007-10-04 14:04:40 -0400 | [diff] [blame] | 121 | if (dev != sdata->local->mdev) |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 122 | dev->hard_start_xmit = ieee80211_subif_start_xmit; |
Johannes Berg | 40f7cac | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 123 | |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 124 | /* |
| 125 | * Called even when register_netdevice fails, it would |
| 126 | * oops if assigned before initialising the rest. |
| 127 | */ |
| 128 | dev->uninit = ieee80211_if_reinit; |
| 129 | |
| 130 | /* most have no BSS pointer */ |
| 131 | sdata->bss = NULL; |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 132 | sdata->vif.type = type; |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 133 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 134 | sdata->basic_rates = 0; |
| 135 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 136 | switch (type) { |
| 137 | case IEEE80211_IF_TYPE_WDS: |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 138 | /* nothing special */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 139 | break; |
| 140 | case IEEE80211_IF_TYPE_VLAN: |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 141 | sdata->u.vlan.ap = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 142 | break; |
| 143 | case IEEE80211_IF_TYPE_AP: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 144 | sdata->u.ap.force_unicast_rateidx = -1; |
| 145 | sdata->u.ap.max_ratectrl_rateidx = -1; |
| 146 | skb_queue_head_init(&sdata->u.ap.ps_bc_buf); |
| 147 | sdata->bss = &sdata->u.ap; |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 148 | INIT_LIST_HEAD(&sdata->u.ap.vlans); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 149 | break; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame^] | 150 | case IEEE80211_IF_TYPE_MESH_POINT: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 151 | case IEEE80211_IF_TYPE_STA: |
| 152 | case IEEE80211_IF_TYPE_IBSS: { |
| 153 | struct ieee80211_sub_if_data *msdata; |
| 154 | struct ieee80211_if_sta *ifsta; |
| 155 | |
| 156 | ifsta = &sdata->u.sta; |
| 157 | INIT_WORK(&ifsta->work, ieee80211_sta_work); |
| 158 | setup_timer(&ifsta->timer, ieee80211_sta_timer, |
| 159 | (unsigned long) sdata); |
| 160 | skb_queue_head_init(&ifsta->skb_queue); |
| 161 | |
| 162 | ifsta->capab = WLAN_CAPABILITY_ESS; |
| 163 | ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN | |
| 164 | IEEE80211_AUTH_ALG_SHARED_KEY; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 165 | ifsta->flags |= IEEE80211_STA_CREATE_IBSS | |
| 166 | IEEE80211_STA_WMM_ENABLED | |
| 167 | IEEE80211_STA_AUTO_BSSID_SEL | |
| 168 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 169 | |
| 170 | msdata = IEEE80211_DEV_TO_SUB_IF(sdata->local->mdev); |
| 171 | sdata->bss = &msdata->u.ap; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame^] | 172 | |
| 173 | #ifdef CONFIG_MAC80211_MESH |
| 174 | if (type == IEEE80211_IF_TYPE_MESH_POINT) { |
| 175 | ifsta->mshcfg.dot11MeshRetryTimeout = MESH_RET_T; |
| 176 | ifsta->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T; |
| 177 | ifsta->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T; |
| 178 | ifsta->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR; |
| 179 | ifsta->mshcfg.dot11MeshTTL = MESH_TTL; |
| 180 | ifsta->mshcfg.auto_open_plinks = true; |
| 181 | ifsta->mshcfg.dot11MeshMaxPeerLinks = |
| 182 | MESH_MAX_ESTAB_PLINKS; |
| 183 | ifsta->mshcfg.dot11MeshHWMPactivePathTimeout = |
| 184 | MESH_PATH_TIMEOUT; |
| 185 | ifsta->mshcfg.dot11MeshHWMPpreqMinInterval = |
| 186 | MESH_PREQ_MIN_INT; |
| 187 | ifsta->mshcfg.dot11MeshHWMPnetDiameterTraversalTime = |
| 188 | MESH_DIAM_TRAVERSAL_TIME; |
| 189 | ifsta->mshcfg.dot11MeshHWMPmaxPREQretries = |
| 190 | MESH_MAX_PREQ_RETRIES; |
| 191 | ifsta->mshcfg.path_refresh_time = |
| 192 | MESH_PATH_REFRESH_TIME; |
| 193 | ifsta->mshcfg.min_discovery_timeout = |
| 194 | MESH_MIN_DISCOVERY_TIMEOUT; |
| 195 | ifsta->accepting_plinks = true; |
| 196 | ifsta->preq_id = 0; |
| 197 | ifsta->dsn = 0; |
| 198 | atomic_set(&ifsta->mpaths, 0); |
| 199 | mesh_rmc_init(dev); |
| 200 | ifsta->last_preq = jiffies; |
| 201 | /* Allocate all mesh structures when creating the first |
| 202 | * mesh interface. |
| 203 | */ |
| 204 | if (!mesh_allocated) |
| 205 | ieee80211s_init(); |
| 206 | mesh_ids_set_default(ifsta); |
| 207 | setup_timer(&ifsta->mesh_path_timer, |
| 208 | ieee80211_mesh_path_timer, |
| 209 | (unsigned long) sdata); |
| 210 | INIT_LIST_HEAD(&ifsta->preq_queue.list); |
| 211 | spin_lock_init(&ifsta->mesh_preq_queue_lock); |
| 212 | } |
| 213 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 214 | break; |
| 215 | } |
| 216 | case IEEE80211_IF_TYPE_MNTR: |
| 217 | dev->type = ARPHRD_IEEE80211_RADIOTAP; |
Johannes Berg | 40f7cac | 2007-07-10 19:32:08 +0200 | [diff] [blame] | 218 | dev->hard_start_xmit = ieee80211_monitor_start_xmit; |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 219 | sdata->u.mntr_flags = MONITOR_FLAG_CONTROL | |
| 220 | MONITOR_FLAG_OTHER_BSS; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 221 | break; |
| 222 | default: |
| 223 | printk(KERN_WARNING "%s: %s: Unknown interface type 0x%x", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 224 | dev->name, __func__, type); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 225 | } |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 226 | ieee80211_debugfs_change_if_type(sdata, oldtype); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* Must be called with rtnl lock held. */ |
| 230 | void ieee80211_if_reinit(struct net_device *dev) |
| 231 | { |
| 232 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 233 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 234 | struct sta_info *sta; |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 235 | struct sk_buff *skb; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 236 | |
| 237 | ASSERT_RTNL(); |
Johannes Berg | 11a843b | 2007-08-28 17:01:55 -0400 | [diff] [blame] | 238 | |
| 239 | ieee80211_free_keys(sdata); |
| 240 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 241 | ieee80211_if_sdata_deinit(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 242 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 243 | switch (sdata->vif.type) { |
Johannes Berg | a289755 | 2007-09-28 14:01:25 +0200 | [diff] [blame] | 244 | case IEEE80211_IF_TYPE_INVALID: |
| 245 | /* cannot happen */ |
| 246 | WARN_ON(1); |
| 247 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 248 | case IEEE80211_IF_TYPE_AP: { |
| 249 | /* Remove all virtual interfaces that use this BSS |
| 250 | * as their sdata->bss */ |
| 251 | struct ieee80211_sub_if_data *tsdata, *n; |
Johannes Berg | e6a5ddf | 2008-02-25 16:27:42 +0100 | [diff] [blame] | 252 | struct beacon_data *beacon; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 253 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 254 | list_for_each_entry_safe(tsdata, n, &local->interfaces, list) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 255 | if (tsdata != sdata && tsdata->bss == &sdata->u.ap) { |
| 256 | printk(KERN_DEBUG "%s: removing virtual " |
| 257 | "interface %s because its BSS interface" |
| 258 | " is being removed\n", |
| 259 | sdata->dev->name, tsdata->dev->name); |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 260 | list_del_rcu(&tsdata->list); |
| 261 | /* |
| 262 | * We have lots of time and can afford |
| 263 | * to sync for each interface |
| 264 | */ |
| 265 | synchronize_rcu(); |
| 266 | __ieee80211_if_del(local, tsdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 269 | |
Johannes Berg | e6a5ddf | 2008-02-25 16:27:42 +0100 | [diff] [blame] | 270 | beacon = sdata->u.ap.beacon; |
| 271 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 272 | synchronize_rcu(); |
| 273 | kfree(beacon); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 274 | |
Johannes Berg | 5b2812e | 2007-09-26 14:27:23 +0200 | [diff] [blame] | 275 | while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) { |
| 276 | local->total_ps_buffered--; |
| 277 | dev_kfree_skb(skb); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | break; |
| 281 | } |
| 282 | case IEEE80211_IF_TYPE_WDS: |
| 283 | sta = sta_info_get(local, sdata->u.wds.remote_addr); |
| 284 | if (sta) { |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 285 | sta_info_free(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 286 | sta_info_put(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 287 | } else { |
| 288 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 289 | printk(KERN_DEBUG "%s: Someone had deleted my STA " |
| 290 | "entry for the WDS link\n", dev->name); |
| 291 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
| 292 | } |
| 293 | break; |
Johannes Berg | 6032f93 | 2008-02-23 15:17:07 +0100 | [diff] [blame] | 294 | case IEEE80211_IF_TYPE_MESH_POINT: |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame^] | 295 | #ifdef CONFIG_MAC80211_MESH |
| 296 | mesh_rmc_free(dev); |
| 297 | #endif |
| 298 | /* fall through */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 299 | case IEEE80211_IF_TYPE_STA: |
| 300 | case IEEE80211_IF_TYPE_IBSS: |
| 301 | kfree(sdata->u.sta.extra_ie); |
| 302 | sdata->u.sta.extra_ie = NULL; |
| 303 | kfree(sdata->u.sta.assocreq_ies); |
| 304 | sdata->u.sta.assocreq_ies = NULL; |
| 305 | kfree(sdata->u.sta.assocresp_ies); |
| 306 | sdata->u.sta.assocresp_ies = NULL; |
| 307 | if (sdata->u.sta.probe_resp) { |
| 308 | dev_kfree_skb(sdata->u.sta.probe_resp); |
| 309 | sdata->u.sta.probe_resp = NULL; |
| 310 | } |
| 311 | |
| 312 | break; |
| 313 | case IEEE80211_IF_TYPE_MNTR: |
| 314 | dev->type = ARPHRD_ETHER; |
| 315 | break; |
Johannes Berg | 0ec3ca4 | 2007-09-17 01:29:24 -0400 | [diff] [blame] | 316 | case IEEE80211_IF_TYPE_VLAN: |
| 317 | sdata->u.vlan.ap = NULL; |
| 318 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /* remove all STAs that are bound to this virtual interface */ |
| 322 | sta_info_flush(local, dev); |
| 323 | |
| 324 | memset(&sdata->u, 0, sizeof(sdata->u)); |
| 325 | ieee80211_if_sdata_init(sdata); |
| 326 | } |
| 327 | |
| 328 | /* Must be called with rtnl lock held. */ |
| 329 | void __ieee80211_if_del(struct ieee80211_local *local, |
| 330 | struct ieee80211_sub_if_data *sdata) |
| 331 | { |
| 332 | struct net_device *dev = sdata->dev; |
| 333 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 334 | ieee80211_debugfs_remove_netdev(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 335 | unregister_netdevice(dev); |
| 336 | /* Except master interface, the net_device will be freed by |
| 337 | * net_device->destructor (i. e. ieee80211_if_free). */ |
| 338 | } |
| 339 | |
| 340 | /* Must be called with rtnl lock held. */ |
| 341 | int ieee80211_if_remove(struct net_device *dev, const char *name, int id) |
| 342 | { |
| 343 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 344 | struct ieee80211_sub_if_data *sdata, *n; |
| 345 | |
| 346 | ASSERT_RTNL(); |
| 347 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 348 | list_for_each_entry_safe(sdata, n, &local->interfaces, list) { |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 349 | if ((sdata->vif.type == id || id == -1) && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 350 | strcmp(name, sdata->dev->name) == 0 && |
| 351 | sdata->dev != local->mdev) { |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 352 | list_del_rcu(&sdata->list); |
| 353 | synchronize_rcu(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 354 | __ieee80211_if_del(local, sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 355 | return 0; |
| 356 | } |
| 357 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 358 | return -ENODEV; |
| 359 | } |
| 360 | |
| 361 | void ieee80211_if_free(struct net_device *dev) |
| 362 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 363 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 364 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 365 | ieee80211_if_sdata_deinit(sdata); |
| 366 | free_netdev(dev); |
| 367 | } |