1f0706e82SJiri Benc /* 2f0706e82SJiri Benc * Copyright 2002-2005, Instant802 Networks, Inc. 3f0706e82SJiri Benc * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 4f0706e82SJiri Benc * 5f0706e82SJiri Benc * This program is free software; you can redistribute it and/or modify 6f0706e82SJiri Benc * it under the terms of the GNU General Public License version 2 as 7f0706e82SJiri Benc * published by the Free Software Foundation. 8f0706e82SJiri Benc */ 9f0706e82SJiri Benc 10f0706e82SJiri Benc #include <linux/module.h> 11f0706e82SJiri Benc #include <linux/init.h> 12888d04dfSFelix Fietkau #include <linux/etherdevice.h> 13f0706e82SJiri Benc #include <linux/netdevice.h> 14f0706e82SJiri Benc #include <linux/types.h> 15f0706e82SJiri Benc #include <linux/slab.h> 16f0706e82SJiri Benc #include <linux/skbuff.h> 17f0706e82SJiri Benc #include <linux/if_arp.h> 180d174406SJohannes Berg #include <linux/timer.h> 19d0709a65SJohannes Berg #include <linux/rtnetlink.h> 20f0706e82SJiri Benc 21f0706e82SJiri Benc #include <net/mac80211.h> 22f0706e82SJiri Benc #include "ieee80211_i.h" 2324487981SJohannes Berg #include "driver-ops.h" 242c8dccc7SJohannes Berg #include "rate.h" 25f0706e82SJiri Benc #include "sta_info.h" 26e9f207f0SJiri Benc #include "debugfs_sta.h" 27ee385855SLuis Carlos Cobo #include "mesh.h" 28ce662b44SJohannes Berg #include "wme.h" 29f0706e82SJiri Benc 30d0709a65SJohannes Berg /** 31d0709a65SJohannes Berg * DOC: STA information lifetime rules 32d0709a65SJohannes Berg * 33d0709a65SJohannes Berg * STA info structures (&struct sta_info) are managed in a hash table 34d0709a65SJohannes Berg * for faster lookup and a list for iteration. They are managed using 35d0709a65SJohannes Berg * RCU, i.e. access to the list and hash table is protected by RCU. 36d0709a65SJohannes Berg * 3734e89507SJohannes Berg * Upon allocating a STA info structure with sta_info_alloc(), the caller 3834e89507SJohannes Berg * owns that structure. It must then insert it into the hash table using 3934e89507SJohannes Berg * either sta_info_insert() or sta_info_insert_rcu(); only in the latter 4034e89507SJohannes Berg * case (which acquires an rcu read section but must not be called from 4134e89507SJohannes Berg * within one) will the pointer still be valid after the call. Note that 4234e89507SJohannes Berg * the caller may not do much with the STA info before inserting it, in 4334e89507SJohannes Berg * particular, it may not start any mesh peer link management or add 4434e89507SJohannes Berg * encryption keys. 4593e5deb1SJohannes Berg * 4693e5deb1SJohannes Berg * When the insertion fails (sta_info_insert()) returns non-zero), the 4793e5deb1SJohannes Berg * structure will have been freed by sta_info_insert()! 48d0709a65SJohannes Berg * 4934e89507SJohannes Berg * Station entries are added by mac80211 when you establish a link with a 507e189a12SLuis R. Rodriguez * peer. This means different things for the different type of interfaces 517e189a12SLuis R. Rodriguez * we support. For a regular station this mean we add the AP sta when we 5225985edcSLucas De Marchi * receive an association response from the AP. For IBSS this occurs when 5334e89507SJohannes Berg * get to know about a peer on the same IBSS. For WDS we add the sta for 5425985edcSLucas De Marchi * the peer immediately upon device open. When using AP mode we add stations 5534e89507SJohannes Berg * for each respective station upon request from userspace through nl80211. 567e189a12SLuis R. Rodriguez * 5734e89507SJohannes Berg * In order to remove a STA info structure, various sta_info_destroy_*() 5834e89507SJohannes Berg * calls are available. 59d0709a65SJohannes Berg * 6034e89507SJohannes Berg * There is no concept of ownership on a STA entry, each structure is 6134e89507SJohannes Berg * owned by the global hash table/list until it is removed. All users of 6234e89507SJohannes Berg * the structure need to be RCU protected so that the structure won't be 6334e89507SJohannes Berg * freed before they are done using it. 64d0709a65SJohannes Berg */ 65f0706e82SJiri Benc 664d33960bSJohannes Berg /* Caller must hold local->sta_mtx */ 67be8755e1SMichael Wu static int sta_info_hash_del(struct ieee80211_local *local, 68f0706e82SJiri Benc struct sta_info *sta) 69f0706e82SJiri Benc { 70f0706e82SJiri Benc struct sta_info *s; 71f0706e82SJiri Benc 7240b275b6SJohannes Berg s = rcu_dereference_protected(local->sta_hash[STA_HASH(sta->sta.addr)], 734d33960bSJohannes Berg lockdep_is_held(&local->sta_mtx)); 74f0706e82SJiri Benc if (!s) 75be8755e1SMichael Wu return -ENOENT; 76be8755e1SMichael Wu if (s == sta) { 77cf778b00SEric Dumazet rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], 78d0709a65SJohannes Berg s->hnext); 79be8755e1SMichael Wu return 0; 80f0706e82SJiri Benc } 81f0706e82SJiri Benc 8240b275b6SJohannes Berg while (rcu_access_pointer(s->hnext) && 8340b275b6SJohannes Berg rcu_access_pointer(s->hnext) != sta) 8440b275b6SJohannes Berg s = rcu_dereference_protected(s->hnext, 854d33960bSJohannes Berg lockdep_is_held(&local->sta_mtx)); 8640b275b6SJohannes Berg if (rcu_access_pointer(s->hnext)) { 87cf778b00SEric Dumazet rcu_assign_pointer(s->hnext, sta->hnext); 88be8755e1SMichael Wu return 0; 89f0706e82SJiri Benc } 90f0706e82SJiri Benc 91be8755e1SMichael Wu return -ENOENT; 92f0706e82SJiri Benc } 93f0706e82SJiri Benc 9497f97b1fSJohannes Berg static void cleanup_single_sta(struct sta_info *sta) 95b22cfcfcSEliad Peller { 96b22cfcfcSEliad Peller int ac, i; 97b22cfcfcSEliad Peller struct tid_ampdu_tx *tid_tx; 98b22cfcfcSEliad Peller struct ieee80211_sub_if_data *sdata = sta->sdata; 99b22cfcfcSEliad Peller struct ieee80211_local *local = sdata->local; 100d012a605SMarco Porsch struct ps_data *ps; 101b22cfcfcSEliad Peller 102b22cfcfcSEliad Peller /* 103b22cfcfcSEliad Peller * At this point, when being called as call_rcu callback, 104b22cfcfcSEliad Peller * neither mac80211 nor the driver can reference this 105b22cfcfcSEliad Peller * sta struct any more except by still existing timers 106b22cfcfcSEliad Peller * associated with this station that we clean up below. 107051007d9SJohannes Berg * 108051007d9SJohannes Berg * Note though that this still uses the sdata and even 109051007d9SJohannes Berg * calls the driver in AP and mesh mode, so interfaces 110051007d9SJohannes Berg * of those types mush use call sta_info_flush_cleanup() 111051007d9SJohannes Berg * (typically via sta_info_flush()) before deconfiguring 112051007d9SJohannes Berg * the driver. 113051007d9SJohannes Berg * 114051007d9SJohannes Berg * In station mode, nothing happens here so it doesn't 115051007d9SJohannes Berg * have to (and doesn't) do that, this is intentional to 116051007d9SJohannes Berg * speed up roaming. 117b22cfcfcSEliad Peller */ 118b22cfcfcSEliad Peller 119b22cfcfcSEliad Peller if (test_sta_flag(sta, WLAN_STA_PS_STA)) { 120d012a605SMarco Porsch if (sta->sdata->vif.type == NL80211_IFTYPE_AP || 121d012a605SMarco Porsch sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 122d012a605SMarco Porsch ps = &sdata->bss->ps; 123*3f52b7e3SMarco Porsch else if (ieee80211_vif_is_mesh(&sdata->vif)) 124*3f52b7e3SMarco Porsch ps = &sdata->u.mesh.ps; 125d012a605SMarco Porsch else 126d012a605SMarco Porsch return; 127b22cfcfcSEliad Peller 128b22cfcfcSEliad Peller clear_sta_flag(sta, WLAN_STA_PS_STA); 129b22cfcfcSEliad Peller 130d012a605SMarco Porsch atomic_dec(&ps->num_sta_ps); 131b22cfcfcSEliad Peller sta_info_recalc_tim(sta); 132b22cfcfcSEliad Peller } 133b22cfcfcSEliad Peller 134b22cfcfcSEliad Peller for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 135b22cfcfcSEliad Peller local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]); 1361f98ab7fSFelix Fietkau ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]); 1371f98ab7fSFelix Fietkau ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]); 138b22cfcfcSEliad Peller } 139b22cfcfcSEliad Peller 140b22cfcfcSEliad Peller #ifdef CONFIG_MAC80211_MESH 141b22cfcfcSEliad Peller if (ieee80211_vif_is_mesh(&sdata->vif)) { 142b22cfcfcSEliad Peller mesh_accept_plinks_update(sdata); 143b22cfcfcSEliad Peller mesh_plink_deactivate(sta); 144b22cfcfcSEliad Peller del_timer_sync(&sta->plink_timer); 145b22cfcfcSEliad Peller } 146b22cfcfcSEliad Peller #endif 147b22cfcfcSEliad Peller 148b22cfcfcSEliad Peller cancel_work_sync(&sta->drv_unblock_wk); 149b22cfcfcSEliad Peller 150b22cfcfcSEliad Peller /* 151b22cfcfcSEliad Peller * Destroy aggregation state here. It would be nice to wait for the 152b22cfcfcSEliad Peller * driver to finish aggregation stop and then clean up, but for now 153b22cfcfcSEliad Peller * drivers have to handle aggregation stop being requested, followed 154b22cfcfcSEliad Peller * directly by station destruction. 155b22cfcfcSEliad Peller */ 1565a306f58SJohannes Berg for (i = 0; i < IEEE80211_NUM_TIDS; i++) { 157b22cfcfcSEliad Peller tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]); 158b22cfcfcSEliad Peller if (!tid_tx) 159b22cfcfcSEliad Peller continue; 1601f98ab7fSFelix Fietkau ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending); 161b22cfcfcSEliad Peller kfree(tid_tx); 162b22cfcfcSEliad Peller } 163b22cfcfcSEliad Peller 164b22cfcfcSEliad Peller sta_info_free(local, sta); 165b22cfcfcSEliad Peller } 166b22cfcfcSEliad Peller 16797f97b1fSJohannes Berg void ieee80211_cleanup_sdata_stas(struct ieee80211_sub_if_data *sdata) 16897f97b1fSJohannes Berg { 16997f97b1fSJohannes Berg struct sta_info *sta; 17097f97b1fSJohannes Berg 17197f97b1fSJohannes Berg spin_lock_bh(&sdata->cleanup_stations_lock); 17297f97b1fSJohannes Berg while (!list_empty(&sdata->cleanup_stations)) { 17397f97b1fSJohannes Berg sta = list_first_entry(&sdata->cleanup_stations, 17497f97b1fSJohannes Berg struct sta_info, list); 17597f97b1fSJohannes Berg list_del(&sta->list); 17697f97b1fSJohannes Berg spin_unlock_bh(&sdata->cleanup_stations_lock); 17797f97b1fSJohannes Berg 17897f97b1fSJohannes Berg cleanup_single_sta(sta); 17997f97b1fSJohannes Berg 18097f97b1fSJohannes Berg spin_lock_bh(&sdata->cleanup_stations_lock); 18197f97b1fSJohannes Berg } 18297f97b1fSJohannes Berg 18397f97b1fSJohannes Berg spin_unlock_bh(&sdata->cleanup_stations_lock); 18497f97b1fSJohannes Berg } 18597f97b1fSJohannes Berg 186b22cfcfcSEliad Peller static void free_sta_rcu(struct rcu_head *h) 187b22cfcfcSEliad Peller { 188b22cfcfcSEliad Peller struct sta_info *sta = container_of(h, struct sta_info, rcu_head); 18997f97b1fSJohannes Berg struct ieee80211_sub_if_data *sdata = sta->sdata; 190b22cfcfcSEliad Peller 19197f97b1fSJohannes Berg spin_lock(&sdata->cleanup_stations_lock); 19297f97b1fSJohannes Berg list_add_tail(&sta->list, &sdata->cleanup_stations); 19397f97b1fSJohannes Berg spin_unlock(&sdata->cleanup_stations_lock); 19497f97b1fSJohannes Berg 19597f97b1fSJohannes Berg ieee80211_queue_work(&sdata->local->hw, &sdata->cleanup_stations_wk); 196b22cfcfcSEliad Peller } 197b22cfcfcSEliad Peller 198d0709a65SJohannes Berg /* protected by RCU */ 199abe60632SJohannes Berg struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata, 200abe60632SJohannes Berg const u8 *addr) 20143ba7e95SJohannes Berg { 202abe60632SJohannes Berg struct ieee80211_local *local = sdata->local; 20343ba7e95SJohannes Berg struct sta_info *sta; 20443ba7e95SJohannes Berg 2050379185bSJohannes Berg sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], 2060379185bSJohannes Berg lockdep_is_held(&local->sta_mtx)); 20743ba7e95SJohannes Berg while (sta) { 208abe60632SJohannes Berg if (sta->sdata == sdata && 209b203ca39SJoe Perches ether_addr_equal(sta->sta.addr, addr)) 21043ba7e95SJohannes Berg break; 2110379185bSJohannes Berg sta = rcu_dereference_check(sta->hnext, 2120379185bSJohannes Berg lockdep_is_held(&local->sta_mtx)); 21343ba7e95SJohannes Berg } 21443ba7e95SJohannes Berg return sta; 21543ba7e95SJohannes Berg } 21643ba7e95SJohannes Berg 2170e5ded5aSFelix Fietkau /* 2180e5ded5aSFelix Fietkau * Get sta info either from the specified interface 2190e5ded5aSFelix Fietkau * or from one of its vlans 2200e5ded5aSFelix Fietkau */ 2210e5ded5aSFelix Fietkau struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata, 2220e5ded5aSFelix Fietkau const u8 *addr) 2230e5ded5aSFelix Fietkau { 2240e5ded5aSFelix Fietkau struct ieee80211_local *local = sdata->local; 2250e5ded5aSFelix Fietkau struct sta_info *sta; 2260e5ded5aSFelix Fietkau 2270379185bSJohannes Berg sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)], 2280379185bSJohannes Berg lockdep_is_held(&local->sta_mtx)); 2290e5ded5aSFelix Fietkau while (sta) { 2300e5ded5aSFelix Fietkau if ((sta->sdata == sdata || 231a2c1e3daSJohannes Berg (sta->sdata->bss && sta->sdata->bss == sdata->bss)) && 232b203ca39SJoe Perches ether_addr_equal(sta->sta.addr, addr)) 2330e5ded5aSFelix Fietkau break; 2340379185bSJohannes Berg sta = rcu_dereference_check(sta->hnext, 2350379185bSJohannes Berg lockdep_is_held(&local->sta_mtx)); 2360e5ded5aSFelix Fietkau } 2370e5ded5aSFelix Fietkau return sta; 2380e5ded5aSFelix Fietkau } 2390e5ded5aSFelix Fietkau 2403b53fde8SJohannes Berg struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata, 2413b53fde8SJohannes Berg int idx) 242ee385855SLuis Carlos Cobo { 2433b53fde8SJohannes Berg struct ieee80211_local *local = sdata->local; 244ee385855SLuis Carlos Cobo struct sta_info *sta; 245ee385855SLuis Carlos Cobo int i = 0; 246ee385855SLuis Carlos Cobo 247d0709a65SJohannes Berg list_for_each_entry_rcu(sta, &local->sta_list, list) { 2483b53fde8SJohannes Berg if (sdata != sta->sdata) 2492a8ca29aSLuis Carlos Cobo continue; 250ee385855SLuis Carlos Cobo if (i < idx) { 251ee385855SLuis Carlos Cobo ++i; 252ee385855SLuis Carlos Cobo continue; 253ee385855SLuis Carlos Cobo } 2542a8ca29aSLuis Carlos Cobo return sta; 255ee385855SLuis Carlos Cobo } 256ee385855SLuis Carlos Cobo 257ee385855SLuis Carlos Cobo return NULL; 258ee385855SLuis Carlos Cobo } 259f0706e82SJiri Benc 26093e5deb1SJohannes Berg /** 261d9a7ddb0SJohannes Berg * sta_info_free - free STA 26293e5deb1SJohannes Berg * 2636ef307bcSRandy Dunlap * @local: pointer to the global information 26493e5deb1SJohannes Berg * @sta: STA info to free 26593e5deb1SJohannes Berg * 26693e5deb1SJohannes Berg * This function must undo everything done by sta_info_alloc() 267d9a7ddb0SJohannes Berg * that may happen before sta_info_insert(). It may only be 268d9a7ddb0SJohannes Berg * called when sta_info_insert() has not been attempted (and 269d9a7ddb0SJohannes Berg * if that fails, the station is freed anyway.) 27093e5deb1SJohannes Berg */ 271d9a7ddb0SJohannes Berg void sta_info_free(struct ieee80211_local *local, struct sta_info *sta) 27293e5deb1SJohannes Berg { 273889cbb91SJohannes Berg if (sta->rate_ctrl) 2744b7679a5SJohannes Berg rate_control_free_sta(sta); 27593e5deb1SJohannes Berg 276bdcbd8e0SJohannes Berg sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr); 27793e5deb1SJohannes Berg 27893e5deb1SJohannes Berg kfree(sta); 27993e5deb1SJohannes Berg } 28093e5deb1SJohannes Berg 2814d33960bSJohannes Berg /* Caller must hold local->sta_mtx */ 282d0709a65SJohannes Berg static void sta_info_hash_add(struct ieee80211_local *local, 283d0709a65SJohannes Berg struct sta_info *sta) 284f0706e82SJiri Benc { 2854d33960bSJohannes Berg lockdep_assert_held(&local->sta_mtx); 28617741cdcSJohannes Berg sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)]; 287cf778b00SEric Dumazet rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta); 288f0706e82SJiri Benc } 289f0706e82SJiri Benc 290af818581SJohannes Berg static void sta_unblock(struct work_struct *wk) 291af818581SJohannes Berg { 292af818581SJohannes Berg struct sta_info *sta; 293af818581SJohannes Berg 294af818581SJohannes Berg sta = container_of(wk, struct sta_info, drv_unblock_wk); 295af818581SJohannes Berg 296af818581SJohannes Berg if (sta->dead) 297af818581SJohannes Berg return; 298af818581SJohannes Berg 29954420473SHelmut Schaa if (!test_sta_flag(sta, WLAN_STA_PS_STA)) { 30054420473SHelmut Schaa local_bh_disable(); 301af818581SJohannes Berg ieee80211_sta_ps_deliver_wakeup(sta); 30254420473SHelmut Schaa local_bh_enable(); 30354420473SHelmut Schaa } else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL)) { 304c2c98fdeSJohannes Berg clear_sta_flag(sta, WLAN_STA_PS_DRIVER); 305ce662b44SJohannes Berg 306ce662b44SJohannes Berg local_bh_disable(); 307af818581SJohannes Berg ieee80211_sta_ps_deliver_poll_response(sta); 308ce662b44SJohannes Berg local_bh_enable(); 309c2c98fdeSJohannes Berg } else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD)) { 310c2c98fdeSJohannes Berg clear_sta_flag(sta, WLAN_STA_PS_DRIVER); 311ce662b44SJohannes Berg 312ce662b44SJohannes Berg local_bh_disable(); 31347086fc5SJohannes Berg ieee80211_sta_ps_deliver_uapsd(sta); 314ce662b44SJohannes Berg local_bh_enable(); 31550a9432dSJohannes Berg } else 316c2c98fdeSJohannes Berg clear_sta_flag(sta, WLAN_STA_PS_DRIVER); 317af818581SJohannes Berg } 318af818581SJohannes Berg 319af65cd96SJohannes Berg static int sta_prepare_rate_control(struct ieee80211_local *local, 320af65cd96SJohannes Berg struct sta_info *sta, gfp_t gfp) 321af65cd96SJohannes Berg { 322af65cd96SJohannes Berg if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) 323af65cd96SJohannes Berg return 0; 324af65cd96SJohannes Berg 325889cbb91SJohannes Berg sta->rate_ctrl = local->rate_ctrl; 326af65cd96SJohannes Berg sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, 327af65cd96SJohannes Berg &sta->sta, gfp); 328889cbb91SJohannes Berg if (!sta->rate_ctrl_priv) 329af65cd96SJohannes Berg return -ENOMEM; 330af65cd96SJohannes Berg 331af65cd96SJohannes Berg return 0; 332af65cd96SJohannes Berg } 333af65cd96SJohannes Berg 33473651ee6SJohannes Berg struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, 33556544160SJohannes Berg const u8 *addr, gfp_t gfp) 336f0706e82SJiri Benc { 337d0709a65SJohannes Berg struct ieee80211_local *local = sdata->local; 338f0706e82SJiri Benc struct sta_info *sta; 339ebe27c91SMohammed Shafi Shajakhan struct timespec uptime; 34016c5f15cSRon Rindjunsky int i; 341f0706e82SJiri Benc 34217741cdcSJohannes Berg sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp); 343f0706e82SJiri Benc if (!sta) 34473651ee6SJohannes Berg return NULL; 345f0706e82SJiri Benc 34607346f81SJohannes Berg spin_lock_init(&sta->lock); 347af818581SJohannes Berg INIT_WORK(&sta->drv_unblock_wk, sta_unblock); 34867c282c0SJohannes Berg INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work); 349a93e3644SJohannes Berg mutex_init(&sta->ampdu_mlme.mtx); 35007346f81SJohannes Berg 35117741cdcSJohannes Berg memcpy(sta->sta.addr, addr, ETH_ALEN); 352d0709a65SJohannes Berg sta->local = local; 353d0709a65SJohannes Berg sta->sdata = sdata; 3548bc8aecdSFelix Fietkau sta->last_rx = jiffies; 355f0706e82SJiri Benc 35671ec375cSJohannes Berg sta->sta_state = IEEE80211_STA_NONE; 35771ec375cSJohannes Berg 358ebe27c91SMohammed Shafi Shajakhan do_posix_clock_monotonic_gettime(&uptime); 359ebe27c91SMohammed Shafi Shajakhan sta->last_connected = uptime.tv_sec; 360541a45a1SBruno Randolf ewma_init(&sta->avg_signal, 1024, 8); 361541a45a1SBruno Randolf 362af65cd96SJohannes Berg if (sta_prepare_rate_control(local, sta, gfp)) { 363f0706e82SJiri Benc kfree(sta); 36473651ee6SJohannes Berg return NULL; 365f0706e82SJiri Benc } 366f0706e82SJiri Benc 3675a306f58SJohannes Berg for (i = 0; i < IEEE80211_NUM_TIDS; i++) { 368a622ab72SJohannes Berg /* 369a622ab72SJohannes Berg * timer_to_tid must be initialized with identity mapping 370a622ab72SJohannes Berg * to enable session_timer's data differentiation. See 371a622ab72SJohannes Berg * sta_rx_agg_session_timer_expired for usage. 372a622ab72SJohannes Berg */ 37316c5f15cSRon Rindjunsky sta->timer_to_tid[i] = i; 37416c5f15cSRon Rindjunsky } 375948d887dSJohannes Berg for (i = 0; i < IEEE80211_NUM_ACS; i++) { 376948d887dSJohannes Berg skb_queue_head_init(&sta->ps_tx_buf[i]); 377948d887dSJohannes Berg skb_queue_head_init(&sta->tx_filtered[i]); 378948d887dSJohannes Berg } 37973651ee6SJohannes Berg 3805a306f58SJohannes Berg for (i = 0; i < IEEE80211_NUM_TIDS; i++) 3814be929beSAlexey Dobriyan sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX); 382cccaec98SSenthil Balasubramanian 383bdcbd8e0SJohannes Berg sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr); 38473651ee6SJohannes Berg 38573651ee6SJohannes Berg return sta; 38673651ee6SJohannes Berg } 38773651ee6SJohannes Berg 3888c71df7aSGuy Eilam static int sta_info_insert_check(struct sta_info *sta) 38934e89507SJohannes Berg { 39034e89507SJohannes Berg struct ieee80211_sub_if_data *sdata = sta->sdata; 39134e89507SJohannes Berg 39203e4497eSJohannes Berg /* 39303e4497eSJohannes Berg * Can't be a WARN_ON because it can be triggered through a race: 39403e4497eSJohannes Berg * something inserts a STA (on one CPU) without holding the RTNL 39503e4497eSJohannes Berg * and another CPU turns off the net device. 39603e4497eSJohannes Berg */ 3978c71df7aSGuy Eilam if (unlikely(!ieee80211_sdata_running(sdata))) 3988c71df7aSGuy Eilam return -ENETDOWN; 39903e4497eSJohannes Berg 400b203ca39SJoe Perches if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) || 4018c71df7aSGuy Eilam is_multicast_ether_addr(sta->sta.addr))) 4028c71df7aSGuy Eilam return -EINVAL; 4038c71df7aSGuy Eilam 4048c71df7aSGuy Eilam return 0; 40593e5deb1SJohannes Berg } 40644213b5eSJohannes Berg 407f09603a2SJohannes Berg static int sta_info_insert_drv_state(struct ieee80211_local *local, 408f09603a2SJohannes Berg struct ieee80211_sub_if_data *sdata, 409f09603a2SJohannes Berg struct sta_info *sta) 410f09603a2SJohannes Berg { 411f09603a2SJohannes Berg enum ieee80211_sta_state state; 412f09603a2SJohannes Berg int err = 0; 413f09603a2SJohannes Berg 414f09603a2SJohannes Berg for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) { 415f09603a2SJohannes Berg err = drv_sta_state(local, sdata, sta, state, state + 1); 416f09603a2SJohannes Berg if (err) 417f09603a2SJohannes Berg break; 418f09603a2SJohannes Berg } 419f09603a2SJohannes Berg 420f09603a2SJohannes Berg if (!err) { 421a4ec45a4SJohannes Berg /* 422a4ec45a4SJohannes Berg * Drivers using legacy sta_add/sta_remove callbacks only 423a4ec45a4SJohannes Berg * get uploaded set to true after sta_add is called. 424a4ec45a4SJohannes Berg */ 425a4ec45a4SJohannes Berg if (!local->ops->sta_add) 426f09603a2SJohannes Berg sta->uploaded = true; 427f09603a2SJohannes Berg return 0; 428f09603a2SJohannes Berg } 429f09603a2SJohannes Berg 430f09603a2SJohannes Berg if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 431bdcbd8e0SJohannes Berg sdata_info(sdata, 432bdcbd8e0SJohannes Berg "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n", 433bdcbd8e0SJohannes Berg sta->sta.addr, state + 1, err); 434f09603a2SJohannes Berg err = 0; 435f09603a2SJohannes Berg } 436f09603a2SJohannes Berg 437f09603a2SJohannes Berg /* unwind on error */ 438f09603a2SJohannes Berg for (; state > IEEE80211_STA_NOTEXIST; state--) 439f09603a2SJohannes Berg WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1)); 440f09603a2SJohannes Berg 441f09603a2SJohannes Berg return err; 442f09603a2SJohannes Berg } 443f09603a2SJohannes Berg 44434e89507SJohannes Berg /* 4458c71df7aSGuy Eilam * should be called with sta_mtx locked 4468c71df7aSGuy Eilam * this function replaces the mutex lock 4478c71df7aSGuy Eilam * with a RCU lock 4488c71df7aSGuy Eilam */ 4494d33960bSJohannes Berg static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU) 4508c71df7aSGuy Eilam { 4518c71df7aSGuy Eilam struct ieee80211_local *local = sta->local; 4528c71df7aSGuy Eilam struct ieee80211_sub_if_data *sdata = sta->sdata; 4537852e361SJohannes Berg struct station_info sinfo; 4548c71df7aSGuy Eilam int err = 0; 4558c71df7aSGuy Eilam 4568c71df7aSGuy Eilam lockdep_assert_held(&local->sta_mtx); 4578c71df7aSGuy Eilam 4587852e361SJohannes Berg /* check if STA exists already */ 4597852e361SJohannes Berg if (sta_info_get_bss(sdata, sta->sta.addr)) { 4604d33960bSJohannes Berg err = -EEXIST; 4614d33960bSJohannes Berg goto out_err; 46234e89507SJohannes Berg } 46334e89507SJohannes Berg 4644d33960bSJohannes Berg /* notify driver */ 465f09603a2SJohannes Berg err = sta_info_insert_drv_state(local, sdata, sta); 466f09603a2SJohannes Berg if (err) 467f09603a2SJohannes Berg goto out_err; 4684d33960bSJohannes Berg 4694d33960bSJohannes Berg local->num_sta++; 4704d33960bSJohannes Berg local->sta_generation++; 4714d33960bSJohannes Berg smp_mb(); 4724d33960bSJohannes Berg 4734d33960bSJohannes Berg /* make the station visible */ 4744d33960bSJohannes Berg sta_info_hash_add(local, sta); 4754d33960bSJohannes Berg 476794454ceSArik Nemtsov list_add_rcu(&sta->list, &local->sta_list); 47783d5cc01SJohannes Berg 47883d5cc01SJohannes Berg set_sta_flag(sta, WLAN_STA_INSERTED); 4794d33960bSJohannes Berg 4804d33960bSJohannes Berg ieee80211_sta_debugfs_add(sta); 4814d33960bSJohannes Berg rate_control_add_sta_debugfs(sta); 4824d33960bSJohannes Berg 4834d33960bSJohannes Berg memset(&sinfo, 0, sizeof(sinfo)); 4844d33960bSJohannes Berg sinfo.filled = 0; 4854d33960bSJohannes Berg sinfo.generation = local->sta_generation; 4864d33960bSJohannes Berg cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL); 487d0709a65SJohannes Berg 488bdcbd8e0SJohannes Berg sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr); 489f0706e82SJiri Benc 49034e89507SJohannes Berg /* move reference to rcu-protected */ 49134e89507SJohannes Berg rcu_read_lock(); 49234e89507SJohannes Berg mutex_unlock(&local->sta_mtx); 493e9f207f0SJiri Benc 49473651ee6SJohannes Berg if (ieee80211_vif_is_mesh(&sdata->vif)) 49573651ee6SJohannes Berg mesh_accept_plinks_update(sdata); 49673651ee6SJohannes Berg 49773651ee6SJohannes Berg return 0; 4984d33960bSJohannes Berg out_err: 4994d33960bSJohannes Berg mutex_unlock(&local->sta_mtx); 5004d33960bSJohannes Berg rcu_read_lock(); 5014d33960bSJohannes Berg return err; 5028c71df7aSGuy Eilam } 5038c71df7aSGuy Eilam 5048c71df7aSGuy Eilam int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU) 5058c71df7aSGuy Eilam { 5068c71df7aSGuy Eilam struct ieee80211_local *local = sta->local; 5078c71df7aSGuy Eilam int err = 0; 5088c71df7aSGuy Eilam 5094d33960bSJohannes Berg might_sleep(); 5104d33960bSJohannes Berg 5118c71df7aSGuy Eilam err = sta_info_insert_check(sta); 5128c71df7aSGuy Eilam if (err) { 5138c71df7aSGuy Eilam rcu_read_lock(); 5148c71df7aSGuy Eilam goto out_free; 5158c71df7aSGuy Eilam } 5168c71df7aSGuy Eilam 517004c872eSJohannes Berg mutex_lock(&local->sta_mtx); 518004c872eSJohannes Berg 5194d33960bSJohannes Berg err = sta_info_insert_finish(sta); 5208c71df7aSGuy Eilam if (err) 521004c872eSJohannes Berg goto out_free; 522d0709a65SJohannes Berg 523004c872eSJohannes Berg return 0; 52493e5deb1SJohannes Berg out_free: 52593e5deb1SJohannes Berg BUG_ON(!err); 526d9a7ddb0SJohannes Berg sta_info_free(local, sta); 52793e5deb1SJohannes Berg return err; 528f0706e82SJiri Benc } 529f0706e82SJiri Benc 53034e89507SJohannes Berg int sta_info_insert(struct sta_info *sta) 53134e89507SJohannes Berg { 53234e89507SJohannes Berg int err = sta_info_insert_rcu(sta); 53334e89507SJohannes Berg 53434e89507SJohannes Berg rcu_read_unlock(); 53534e89507SJohannes Berg 53634e89507SJohannes Berg return err; 53734e89507SJohannes Berg } 53834e89507SJohannes Berg 539d012a605SMarco Porsch static inline void __bss_tim_set(u8 *tim, u16 id) 540004c872eSJohannes Berg { 541004c872eSJohannes Berg /* 542004c872eSJohannes Berg * This format has been mandated by the IEEE specifications, 543004c872eSJohannes Berg * so this line may not be changed to use the __set_bit() format. 544004c872eSJohannes Berg */ 545d012a605SMarco Porsch tim[id / 8] |= (1 << (id % 8)); 546004c872eSJohannes Berg } 547004c872eSJohannes Berg 548d012a605SMarco Porsch static inline void __bss_tim_clear(u8 *tim, u16 id) 549004c872eSJohannes Berg { 550004c872eSJohannes Berg /* 551004c872eSJohannes Berg * This format has been mandated by the IEEE specifications, 552004c872eSJohannes Berg * so this line may not be changed to use the __clear_bit() format. 553004c872eSJohannes Berg */ 554d012a605SMarco Porsch tim[id / 8] &= ~(1 << (id % 8)); 555004c872eSJohannes Berg } 556004c872eSJohannes Berg 557948d887dSJohannes Berg static unsigned long ieee80211_tids_for_ac(int ac) 558004c872eSJohannes Berg { 559948d887dSJohannes Berg /* If we ever support TIDs > 7, this obviously needs to be adjusted */ 560948d887dSJohannes Berg switch (ac) { 561948d887dSJohannes Berg case IEEE80211_AC_VO: 562948d887dSJohannes Berg return BIT(6) | BIT(7); 563948d887dSJohannes Berg case IEEE80211_AC_VI: 564948d887dSJohannes Berg return BIT(4) | BIT(5); 565948d887dSJohannes Berg case IEEE80211_AC_BE: 566948d887dSJohannes Berg return BIT(0) | BIT(3); 567948d887dSJohannes Berg case IEEE80211_AC_BK: 568948d887dSJohannes Berg return BIT(1) | BIT(2); 569948d887dSJohannes Berg default: 570948d887dSJohannes Berg WARN_ON(1); 571948d887dSJohannes Berg return 0; 572d0709a65SJohannes Berg } 573004c872eSJohannes Berg } 574004c872eSJohannes Berg 575c868cb35SJohannes Berg void sta_info_recalc_tim(struct sta_info *sta) 576004c872eSJohannes Berg { 577c868cb35SJohannes Berg struct ieee80211_local *local = sta->local; 578d012a605SMarco Porsch struct ps_data *ps; 579d0709a65SJohannes Berg unsigned long flags; 580948d887dSJohannes Berg bool indicate_tim = false; 581948d887dSJohannes Berg u8 ignore_for_tim = sta->sta.uapsd_queues; 582948d887dSJohannes Berg int ac; 583d012a605SMarco Porsch u16 id; 584004c872eSJohannes Berg 585d012a605SMarco Porsch if (sta->sdata->vif.type == NL80211_IFTYPE_AP || 586d012a605SMarco Porsch sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { 587c868cb35SJohannes Berg if (WARN_ON_ONCE(!sta->sdata->bss)) 588c868cb35SJohannes Berg return; 5893e122be0SJohannes Berg 590d012a605SMarco Porsch ps = &sta->sdata->bss->ps; 591d012a605SMarco Porsch id = sta->sta.aid; 592*3f52b7e3SMarco Porsch #ifdef CONFIG_MAC80211_MESH 593*3f52b7e3SMarco Porsch } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) { 594*3f52b7e3SMarco Porsch ps = &sta->sdata->u.mesh.ps; 595*3f52b7e3SMarco Porsch /* TIM map only for PLID <= IEEE80211_MAX_AID */ 596*3f52b7e3SMarco Porsch id = le16_to_cpu(sta->plid) % IEEE80211_MAX_AID; 597*3f52b7e3SMarco Porsch #endif 598d012a605SMarco Porsch } else { 599d012a605SMarco Porsch return; 600d012a605SMarco Porsch } 601d012a605SMarco Porsch 602c868cb35SJohannes Berg /* No need to do anything if the driver does all */ 603c868cb35SJohannes Berg if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) 604c868cb35SJohannes Berg return; 605004c872eSJohannes Berg 606c868cb35SJohannes Berg if (sta->dead) 607c868cb35SJohannes Berg goto done; 6083e122be0SJohannes Berg 609948d887dSJohannes Berg /* 610948d887dSJohannes Berg * If all ACs are delivery-enabled then we should build 611948d887dSJohannes Berg * the TIM bit for all ACs anyway; if only some are then 612948d887dSJohannes Berg * we ignore those and build the TIM bit using only the 613948d887dSJohannes Berg * non-enabled ones. 614948d887dSJohannes Berg */ 615948d887dSJohannes Berg if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1) 616948d887dSJohannes Berg ignore_for_tim = 0; 617948d887dSJohannes Berg 618948d887dSJohannes Berg for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 619948d887dSJohannes Berg unsigned long tids; 620948d887dSJohannes Berg 621948d887dSJohannes Berg if (ignore_for_tim & BIT(ac)) 622948d887dSJohannes Berg continue; 623948d887dSJohannes Berg 624948d887dSJohannes Berg indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) || 625948d887dSJohannes Berg !skb_queue_empty(&sta->ps_tx_buf[ac]); 626948d887dSJohannes Berg if (indicate_tim) 627948d887dSJohannes Berg break; 628948d887dSJohannes Berg 629948d887dSJohannes Berg tids = ieee80211_tids_for_ac(ac); 630948d887dSJohannes Berg 631948d887dSJohannes Berg indicate_tim |= 632948d887dSJohannes Berg sta->driver_buffered_tids & tids; 633004c872eSJohannes Berg } 634004c872eSJohannes Berg 635c868cb35SJohannes Berg done: 6364d33960bSJohannes Berg spin_lock_irqsave(&local->tim_lock, flags); 637004c872eSJohannes Berg 638948d887dSJohannes Berg if (indicate_tim) 639d012a605SMarco Porsch __bss_tim_set(ps->tim, id); 640c868cb35SJohannes Berg else 641d012a605SMarco Porsch __bss_tim_clear(ps->tim, id); 6423e122be0SJohannes Berg 643c868cb35SJohannes Berg if (local->ops->set_tim) { 644c868cb35SJohannes Berg local->tim_in_locked_section = true; 645948d887dSJohannes Berg drv_set_tim(local, &sta->sta, indicate_tim); 646c868cb35SJohannes Berg local->tim_in_locked_section = false; 647004c872eSJohannes Berg } 648004c872eSJohannes Berg 6494d33960bSJohannes Berg spin_unlock_irqrestore(&local->tim_lock, flags); 650004c872eSJohannes Berg } 651004c872eSJohannes Berg 652cd0b8d89SJohannes Berg static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb) 653f0706e82SJiri Benc { 654e039fa4aSJohannes Berg struct ieee80211_tx_info *info; 655f0706e82SJiri Benc int timeout; 656f0706e82SJiri Benc 657f0706e82SJiri Benc if (!skb) 658cd0b8d89SJohannes Berg return false; 659f0706e82SJiri Benc 660e039fa4aSJohannes Berg info = IEEE80211_SKB_CB(skb); 661f0706e82SJiri Benc 662f0706e82SJiri Benc /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ 66357c4d7b4SJohannes Berg timeout = (sta->listen_interval * 66457c4d7b4SJohannes Berg sta->sdata->vif.bss_conf.beacon_int * 66557c4d7b4SJohannes Berg 32 / 15625) * HZ; 666f0706e82SJiri Benc if (timeout < STA_TX_BUFFER_EXPIRE) 667f0706e82SJiri Benc timeout = STA_TX_BUFFER_EXPIRE; 668e039fa4aSJohannes Berg return time_after(jiffies, info->control.jiffies + timeout); 669f0706e82SJiri Benc } 670f0706e82SJiri Benc 671f0706e82SJiri Benc 672948d887dSJohannes Berg static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local, 673948d887dSJohannes Berg struct sta_info *sta, int ac) 674f0706e82SJiri Benc { 675f0706e82SJiri Benc unsigned long flags; 676f0706e82SJiri Benc struct sk_buff *skb; 677f0706e82SJiri Benc 67860750397SJohannes Berg /* 67960750397SJohannes Berg * First check for frames that should expire on the filtered 68060750397SJohannes Berg * queue. Frames here were rejected by the driver and are on 68160750397SJohannes Berg * a separate queue to avoid reordering with normal PS-buffered 68260750397SJohannes Berg * frames. They also aren't accounted for right now in the 68360750397SJohannes Berg * total_ps_buffered counter. 68460750397SJohannes Berg */ 685f0706e82SJiri Benc for (;;) { 686948d887dSJohannes Berg spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags); 687948d887dSJohannes Berg skb = skb_peek(&sta->tx_filtered[ac]); 68857c4d7b4SJohannes Berg if (sta_info_buffer_expired(sta, skb)) 689948d887dSJohannes Berg skb = __skb_dequeue(&sta->tx_filtered[ac]); 690836341a7SJohannes Berg else 691f0706e82SJiri Benc skb = NULL; 692948d887dSJohannes Berg spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags); 693f0706e82SJiri Benc 69460750397SJohannes Berg /* 69560750397SJohannes Berg * Frames are queued in order, so if this one 69660750397SJohannes Berg * hasn't expired yet we can stop testing. If 69760750397SJohannes Berg * we actually reached the end of the queue we 69860750397SJohannes Berg * also need to stop, of course. 69960750397SJohannes Berg */ 70060750397SJohannes Berg if (!skb) 70160750397SJohannes Berg break; 702d4fa14cdSFelix Fietkau ieee80211_free_txskb(&local->hw, skb); 70360750397SJohannes Berg } 70460750397SJohannes Berg 70560750397SJohannes Berg /* 70660750397SJohannes Berg * Now also check the normal PS-buffered queue, this will 70760750397SJohannes Berg * only find something if the filtered queue was emptied 70860750397SJohannes Berg * since the filtered frames are all before the normal PS 70960750397SJohannes Berg * buffered frames. 71060750397SJohannes Berg */ 711f0706e82SJiri Benc for (;;) { 712948d887dSJohannes Berg spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags); 713948d887dSJohannes Berg skb = skb_peek(&sta->ps_tx_buf[ac]); 714f0706e82SJiri Benc if (sta_info_buffer_expired(sta, skb)) 715948d887dSJohannes Berg skb = __skb_dequeue(&sta->ps_tx_buf[ac]); 716f0706e82SJiri Benc else 717f0706e82SJiri Benc skb = NULL; 718948d887dSJohannes Berg spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags); 719f0706e82SJiri Benc 72060750397SJohannes Berg /* 72160750397SJohannes Berg * frames are queued in order, so if this one 72260750397SJohannes Berg * hasn't expired yet (or we reached the end of 72360750397SJohannes Berg * the queue) we can stop testing 72460750397SJohannes Berg */ 725836341a7SJohannes Berg if (!skb) 726836341a7SJohannes Berg break; 727836341a7SJohannes Berg 728f0706e82SJiri Benc local->total_ps_buffered--; 729bdcbd8e0SJohannes Berg ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n", 730bdcbd8e0SJohannes Berg sta->sta.addr); 731d4fa14cdSFelix Fietkau ieee80211_free_txskb(&local->hw, skb); 732f0706e82SJiri Benc } 7333393a608SJuuso Oikarinen 73460750397SJohannes Berg /* 73560750397SJohannes Berg * Finally, recalculate the TIM bit for this station -- it might 73660750397SJohannes Berg * now be clear because the station was too slow to retrieve its 73760750397SJohannes Berg * frames. 73860750397SJohannes Berg */ 73960750397SJohannes Berg sta_info_recalc_tim(sta); 74060750397SJohannes Berg 74160750397SJohannes Berg /* 74260750397SJohannes Berg * Return whether there are any frames still buffered, this is 74360750397SJohannes Berg * used to check whether the cleanup timer still needs to run, 74460750397SJohannes Berg * if there are no frames we don't need to rearm the timer. 74560750397SJohannes Berg */ 746948d887dSJohannes Berg return !(skb_queue_empty(&sta->ps_tx_buf[ac]) && 747948d887dSJohannes Berg skb_queue_empty(&sta->tx_filtered[ac])); 748948d887dSJohannes Berg } 749948d887dSJohannes Berg 750948d887dSJohannes Berg static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local, 751948d887dSJohannes Berg struct sta_info *sta) 752948d887dSJohannes Berg { 753948d887dSJohannes Berg bool have_buffered = false; 754948d887dSJohannes Berg int ac; 755948d887dSJohannes Berg 756*3f52b7e3SMarco Porsch /* This is only necessary for stations on BSS/MBSS interfaces */ 757*3f52b7e3SMarco Porsch if (!sta->sdata->bss && 758*3f52b7e3SMarco Porsch !ieee80211_vif_is_mesh(&sta->sdata->vif)) 759948d887dSJohannes Berg return false; 760948d887dSJohannes Berg 761948d887dSJohannes Berg for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) 762948d887dSJohannes Berg have_buffered |= 763948d887dSJohannes Berg sta_info_cleanup_expire_buffered_ac(local, sta, ac); 764948d887dSJohannes Berg 765948d887dSJohannes Berg return have_buffered; 766f0706e82SJiri Benc } 767f0706e82SJiri Benc 76883d5cc01SJohannes Berg int __must_check __sta_info_destroy(struct sta_info *sta) 76934e89507SJohannes Berg { 77034e89507SJohannes Berg struct ieee80211_local *local; 77134e89507SJohannes Berg struct ieee80211_sub_if_data *sdata; 772b22cfcfcSEliad Peller int ret, i; 77334e89507SJohannes Berg 77434e89507SJohannes Berg might_sleep(); 77534e89507SJohannes Berg 77634e89507SJohannes Berg if (!sta) 77734e89507SJohannes Berg return -ENOENT; 77834e89507SJohannes Berg 77934e89507SJohannes Berg local = sta->local; 78034e89507SJohannes Berg sdata = sta->sdata; 78134e89507SJohannes Berg 78283d5cc01SJohannes Berg lockdep_assert_held(&local->sta_mtx); 78383d5cc01SJohannes Berg 784098a6070SJohannes Berg /* 785098a6070SJohannes Berg * Before removing the station from the driver and 786098a6070SJohannes Berg * rate control, it might still start new aggregation 787098a6070SJohannes Berg * sessions -- block that to make sure the tear-down 788098a6070SJohannes Berg * will be sufficient. 789098a6070SJohannes Berg */ 790c2c98fdeSJohannes Berg set_sta_flag(sta, WLAN_STA_BLOCK_BA); 791c82c4a80SJohannes Berg ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA); 792098a6070SJohannes Berg 79334e89507SJohannes Berg ret = sta_info_hash_del(local, sta); 79434e89507SJohannes Berg if (ret) 79534e89507SJohannes Berg return ret; 79634e89507SJohannes Berg 797794454ceSArik Nemtsov list_del_rcu(&sta->list); 7984d33960bSJohannes Berg 7998cb23153SJohannes Berg mutex_lock(&local->key_mtx); 800e31b8213SJohannes Berg for (i = 0; i < NUM_DEFAULT_KEYS; i++) 80140b275b6SJohannes Berg __ieee80211_key_free(key_mtx_dereference(local, sta->gtk[i])); 802e31b8213SJohannes Berg if (sta->ptk) 80340b275b6SJohannes Berg __ieee80211_key_free(key_mtx_dereference(local, sta->ptk)); 8048cb23153SJohannes Berg mutex_unlock(&local->key_mtx); 80534e89507SJohannes Berg 80634e89507SJohannes Berg sta->dead = true; 80734e89507SJohannes Berg 80834e89507SJohannes Berg local->num_sta--; 80934e89507SJohannes Berg local->sta_generation++; 81034e89507SJohannes Berg 81134e89507SJohannes Berg if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 812a9b3cd7fSStephen Hemminger RCU_INIT_POINTER(sdata->u.vlan.sta, NULL); 81334e89507SJohannes Berg 81483d5cc01SJohannes Berg while (sta->sta_state > IEEE80211_STA_NONE) { 815f09603a2SJohannes Berg ret = sta_info_move_state(sta, sta->sta_state - 1); 816f09603a2SJohannes Berg if (ret) { 81783d5cc01SJohannes Berg WARN_ON_ONCE(1); 81883d5cc01SJohannes Berg break; 81983d5cc01SJohannes Berg } 82083d5cc01SJohannes Berg } 821d9a7ddb0SJohannes Berg 822f09603a2SJohannes Berg if (sta->uploaded) { 823f09603a2SJohannes Berg ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE, 824f09603a2SJohannes Berg IEEE80211_STA_NOTEXIST); 825f09603a2SJohannes Berg WARN_ON_ONCE(ret != 0); 826f09603a2SJohannes Berg } 82734e89507SJohannes Berg 828bdcbd8e0SJohannes Berg sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr); 829bdcbd8e0SJohannes Berg 830ec15e68bSJouni Malinen cfg80211_del_sta(sdata->dev, sta->sta.addr, GFP_KERNEL); 831ec15e68bSJouni Malinen 83234e89507SJohannes Berg rate_control_remove_sta_debugfs(sta); 83334e89507SJohannes Berg ieee80211_sta_debugfs_remove(sta); 83434e89507SJohannes Berg 835b22cfcfcSEliad Peller call_rcu(&sta->rcu_head, free_sta_rcu); 83634e89507SJohannes Berg 83734e89507SJohannes Berg return 0; 83834e89507SJohannes Berg } 83934e89507SJohannes Berg 84034e89507SJohannes Berg int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr) 84134e89507SJohannes Berg { 84234e89507SJohannes Berg struct sta_info *sta; 84334e89507SJohannes Berg int ret; 84434e89507SJohannes Berg 84534e89507SJohannes Berg mutex_lock(&sdata->local->sta_mtx); 8467852e361SJohannes Berg sta = sta_info_get(sdata, addr); 84734e89507SJohannes Berg ret = __sta_info_destroy(sta); 84834e89507SJohannes Berg mutex_unlock(&sdata->local->sta_mtx); 84934e89507SJohannes Berg 85034e89507SJohannes Berg return ret; 85134e89507SJohannes Berg } 85234e89507SJohannes Berg 85334e89507SJohannes Berg int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata, 85434e89507SJohannes Berg const u8 *addr) 85534e89507SJohannes Berg { 85634e89507SJohannes Berg struct sta_info *sta; 85734e89507SJohannes Berg int ret; 85834e89507SJohannes Berg 85934e89507SJohannes Berg mutex_lock(&sdata->local->sta_mtx); 8607852e361SJohannes Berg sta = sta_info_get_bss(sdata, addr); 86134e89507SJohannes Berg ret = __sta_info_destroy(sta); 86234e89507SJohannes Berg mutex_unlock(&sdata->local->sta_mtx); 86334e89507SJohannes Berg 86434e89507SJohannes Berg return ret; 86534e89507SJohannes Berg } 866f0706e82SJiri Benc 867f0706e82SJiri Benc static void sta_info_cleanup(unsigned long data) 868f0706e82SJiri Benc { 869f0706e82SJiri Benc struct ieee80211_local *local = (struct ieee80211_local *) data; 870f0706e82SJiri Benc struct sta_info *sta; 8713393a608SJuuso Oikarinen bool timer_needed = false; 872f0706e82SJiri Benc 873d0709a65SJohannes Berg rcu_read_lock(); 874d0709a65SJohannes Berg list_for_each_entry_rcu(sta, &local->sta_list, list) 8753393a608SJuuso Oikarinen if (sta_info_cleanup_expire_buffered(local, sta)) 8763393a608SJuuso Oikarinen timer_needed = true; 877d0709a65SJohannes Berg rcu_read_unlock(); 878f0706e82SJiri Benc 8795bb644a0SJohannes Berg if (local->quiescing) 8805bb644a0SJohannes Berg return; 8815bb644a0SJohannes Berg 8823393a608SJuuso Oikarinen if (!timer_needed) 8833393a608SJuuso Oikarinen return; 8843393a608SJuuso Oikarinen 88526d59535SJohannes Berg mod_timer(&local->sta_cleanup, 88626d59535SJohannes Berg round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL)); 887f0706e82SJiri Benc } 888f0706e82SJiri Benc 889f0706e82SJiri Benc void sta_info_init(struct ieee80211_local *local) 890f0706e82SJiri Benc { 8914d33960bSJohannes Berg spin_lock_init(&local->tim_lock); 89234e89507SJohannes Berg mutex_init(&local->sta_mtx); 893f0706e82SJiri Benc INIT_LIST_HEAD(&local->sta_list); 894f0706e82SJiri Benc 895b24b8a24SPavel Emelyanov setup_timer(&local->sta_cleanup, sta_info_cleanup, 896b24b8a24SPavel Emelyanov (unsigned long)local); 897f0706e82SJiri Benc } 898f0706e82SJiri Benc 899f0706e82SJiri Benc void sta_info_stop(struct ieee80211_local *local) 900f0706e82SJiri Benc { 901a56f992cSJohannes Berg del_timer_sync(&local->sta_cleanup); 902f0706e82SJiri Benc } 903f0706e82SJiri Benc 904051007d9SJohannes Berg 905051007d9SJohannes Berg int sta_info_flush_defer(struct ieee80211_sub_if_data *sdata) 906f0706e82SJiri Benc { 907b998e8bbSJohannes Berg struct ieee80211_local *local = sdata->local; 908f0706e82SJiri Benc struct sta_info *sta, *tmp; 90944213b5eSJohannes Berg int ret = 0; 910f0706e82SJiri Benc 911d0709a65SJohannes Berg might_sleep(); 912d0709a65SJohannes Berg 91334e89507SJohannes Berg mutex_lock(&local->sta_mtx); 91434e89507SJohannes Berg list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 915b998e8bbSJohannes Berg if (sdata == sta->sdata) { 91634e89507SJohannes Berg WARN_ON(__sta_info_destroy(sta)); 91734316837SJohannes Berg ret++; 91834316837SJohannes Berg } 91934e89507SJohannes Berg } 92034e89507SJohannes Berg mutex_unlock(&local->sta_mtx); 92144213b5eSJohannes Berg 922051007d9SJohannes Berg return ret; 923051007d9SJohannes Berg } 924051007d9SJohannes Berg 925051007d9SJohannes Berg void sta_info_flush_cleanup(struct ieee80211_sub_if_data *sdata) 926051007d9SJohannes Berg { 92797f97b1fSJohannes Berg ieee80211_cleanup_sdata_stas(sdata); 92897f97b1fSJohannes Berg cancel_work_sync(&sdata->cleanup_stations_wk); 929f0706e82SJiri Benc } 930dc6676b7SJohannes Berg 93124723d1bSJohannes Berg void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, 93224723d1bSJohannes Berg unsigned long exp_time) 93324723d1bSJohannes Berg { 93424723d1bSJohannes Berg struct ieee80211_local *local = sdata->local; 93524723d1bSJohannes Berg struct sta_info *sta, *tmp; 93624723d1bSJohannes Berg 93734e89507SJohannes Berg mutex_lock(&local->sta_mtx); 938e46a2cf9SMohammed Shafi Shajakhan 939e46a2cf9SMohammed Shafi Shajakhan list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 940ec2b774eSMarek Lindner if (sdata != sta->sdata) 941ec2b774eSMarek Lindner continue; 942ec2b774eSMarek Lindner 94324723d1bSJohannes Berg if (time_after(jiffies, sta->last_rx + exp_time)) { 944eea57d42SMohammed Shafi Shajakhan sta_dbg(sta->sdata, "expiring inactive STA %pM\n", 945bdcbd8e0SJohannes Berg sta->sta.addr); 946*3f52b7e3SMarco Porsch 947*3f52b7e3SMarco Porsch if (ieee80211_vif_is_mesh(&sdata->vif) && 948*3f52b7e3SMarco Porsch test_sta_flag(sta, WLAN_STA_PS_STA)) 949*3f52b7e3SMarco Porsch atomic_dec(&sdata->u.mesh.ps.num_sta_ps); 950*3f52b7e3SMarco Porsch 95134e89507SJohannes Berg WARN_ON(__sta_info_destroy(sta)); 95224723d1bSJohannes Berg } 953e46a2cf9SMohammed Shafi Shajakhan } 954e46a2cf9SMohammed Shafi Shajakhan 95534e89507SJohannes Berg mutex_unlock(&local->sta_mtx); 95624723d1bSJohannes Berg } 95717741cdcSJohannes Berg 958686b9cb9SBen Greear struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, 959686b9cb9SBen Greear const u8 *addr, 960686b9cb9SBen Greear const u8 *localaddr) 96117741cdcSJohannes Berg { 962abe60632SJohannes Berg struct sta_info *sta, *nxt; 96317741cdcSJohannes Berg 964686b9cb9SBen Greear /* 965686b9cb9SBen Greear * Just return a random station if localaddr is NULL 966686b9cb9SBen Greear * ... first in list. 967686b9cb9SBen Greear */ 968f7c65594SJohannes Berg for_each_sta_info(hw_to_local(hw), addr, sta, nxt) { 969686b9cb9SBen Greear if (localaddr && 970b203ca39SJoe Perches !ether_addr_equal(sta->sdata->vif.addr, localaddr)) 971686b9cb9SBen Greear continue; 972f7c65594SJohannes Berg if (!sta->uploaded) 973f7c65594SJohannes Berg return NULL; 97417741cdcSJohannes Berg return &sta->sta; 975f7c65594SJohannes Berg } 976f7c65594SJohannes Berg 977abe60632SJohannes Berg return NULL; 97817741cdcSJohannes Berg } 979686b9cb9SBen Greear EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr); 9805ed176e1SJohannes Berg 9815ed176e1SJohannes Berg struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif, 9825ed176e1SJohannes Berg const u8 *addr) 9835ed176e1SJohannes Berg { 984f7c65594SJohannes Berg struct sta_info *sta; 9855ed176e1SJohannes Berg 9865ed176e1SJohannes Berg if (!vif) 9875ed176e1SJohannes Berg return NULL; 9885ed176e1SJohannes Berg 989f7c65594SJohannes Berg sta = sta_info_get_bss(vif_to_sdata(vif), addr); 990f7c65594SJohannes Berg if (!sta) 991f7c65594SJohannes Berg return NULL; 9925ed176e1SJohannes Berg 993f7c65594SJohannes Berg if (!sta->uploaded) 994f7c65594SJohannes Berg return NULL; 995f7c65594SJohannes Berg 996f7c65594SJohannes Berg return &sta->sta; 9975ed176e1SJohannes Berg } 99817741cdcSJohannes Berg EXPORT_SYMBOL(ieee80211_find_sta); 999af818581SJohannes Berg 100050a9432dSJohannes Berg static void clear_sta_ps_flags(void *_sta) 100150a9432dSJohannes Berg { 100250a9432dSJohannes Berg struct sta_info *sta = _sta; 1003608383bfSHelmut Schaa struct ieee80211_sub_if_data *sdata = sta->sdata; 1004d012a605SMarco Porsch struct ps_data *ps; 1005d012a605SMarco Porsch 1006d012a605SMarco Porsch if (sdata->vif.type == NL80211_IFTYPE_AP || 1007d012a605SMarco Porsch sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 1008d012a605SMarco Porsch ps = &sdata->bss->ps; 1009*3f52b7e3SMarco Porsch else if (ieee80211_vif_is_mesh(&sdata->vif)) 1010*3f52b7e3SMarco Porsch ps = &sdata->u.mesh.ps; 1011d012a605SMarco Porsch else 1012d012a605SMarco Porsch return; 101350a9432dSJohannes Berg 1014c2c98fdeSJohannes Berg clear_sta_flag(sta, WLAN_STA_PS_DRIVER); 1015608383bfSHelmut Schaa if (test_and_clear_sta_flag(sta, WLAN_STA_PS_STA)) 1016d012a605SMarco Porsch atomic_dec(&ps->num_sta_ps); 101750a9432dSJohannes Berg } 101850a9432dSJohannes Berg 1019af818581SJohannes Berg /* powersave support code */ 1020af818581SJohannes Berg void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) 1021af818581SJohannes Berg { 1022af818581SJohannes Berg struct ieee80211_sub_if_data *sdata = sta->sdata; 1023af818581SJohannes Berg struct ieee80211_local *local = sdata->local; 1024948d887dSJohannes Berg struct sk_buff_head pending; 1025948d887dSJohannes Berg int filtered = 0, buffered = 0, ac; 1026987c285cSArik Nemtsov unsigned long flags; 1027af818581SJohannes Berg 1028c2c98fdeSJohannes Berg clear_sta_flag(sta, WLAN_STA_SP); 102947086fc5SJohannes Berg 10305a306f58SJohannes Berg BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1); 1031948d887dSJohannes Berg sta->driver_buffered_tids = 0; 1032948d887dSJohannes Berg 1033d057e5a3SArik Nemtsov if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) 103412375ef9SJohannes Berg drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta); 1035af818581SJohannes Berg 1036948d887dSJohannes Berg skb_queue_head_init(&pending); 1037af818581SJohannes Berg 1038af818581SJohannes Berg /* Send all buffered frames to the station */ 1039948d887dSJohannes Berg for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 1040948d887dSJohannes Berg int count = skb_queue_len(&pending), tmp; 1041948d887dSJohannes Berg 1042987c285cSArik Nemtsov spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags); 1043948d887dSJohannes Berg skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending); 1044987c285cSArik Nemtsov spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags); 1045948d887dSJohannes Berg tmp = skb_queue_len(&pending); 1046948d887dSJohannes Berg filtered += tmp - count; 1047948d887dSJohannes Berg count = tmp; 1048948d887dSJohannes Berg 1049987c285cSArik Nemtsov spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags); 1050948d887dSJohannes Berg skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending); 1051987c285cSArik Nemtsov spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags); 1052948d887dSJohannes Berg tmp = skb_queue_len(&pending); 1053948d887dSJohannes Berg buffered += tmp - count; 1054948d887dSJohannes Berg } 1055948d887dSJohannes Berg 1056948d887dSJohannes Berg ieee80211_add_pending_skbs_fn(local, &pending, clear_sta_ps_flags, sta); 1057948d887dSJohannes Berg 1058af818581SJohannes Berg local->total_ps_buffered -= buffered; 1059af818581SJohannes Berg 1060c868cb35SJohannes Berg sta_info_recalc_tim(sta); 1061c868cb35SJohannes Berg 1062bdcbd8e0SJohannes Berg ps_dbg(sdata, 1063bdcbd8e0SJohannes Berg "STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n", 1064bdcbd8e0SJohannes Berg sta->sta.addr, sta->sta.aid, filtered, buffered); 1065af818581SJohannes Berg } 1066af818581SJohannes Berg 1067ce662b44SJohannes Berg static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata, 1068ce662b44SJohannes Berg struct sta_info *sta, int tid, 106940b96408SJohannes Berg enum ieee80211_frame_release_type reason) 1070ce662b44SJohannes Berg { 1071ce662b44SJohannes Berg struct ieee80211_local *local = sdata->local; 1072ce662b44SJohannes Berg struct ieee80211_qos_hdr *nullfunc; 1073ce662b44SJohannes Berg struct sk_buff *skb; 1074ce662b44SJohannes Berg int size = sizeof(*nullfunc); 1075ce662b44SJohannes Berg __le16 fc; 1076c2c98fdeSJohannes Berg bool qos = test_sta_flag(sta, WLAN_STA_WME); 1077ce662b44SJohannes Berg struct ieee80211_tx_info *info; 107855de908aSJohannes Berg struct ieee80211_chanctx_conf *chanctx_conf; 1079ce662b44SJohannes Berg 1080ce662b44SJohannes Berg if (qos) { 1081ce662b44SJohannes Berg fc = cpu_to_le16(IEEE80211_FTYPE_DATA | 1082ce662b44SJohannes Berg IEEE80211_STYPE_QOS_NULLFUNC | 1083ce662b44SJohannes Berg IEEE80211_FCTL_FROMDS); 1084ce662b44SJohannes Berg } else { 1085ce662b44SJohannes Berg size -= 2; 1086ce662b44SJohannes Berg fc = cpu_to_le16(IEEE80211_FTYPE_DATA | 1087ce662b44SJohannes Berg IEEE80211_STYPE_NULLFUNC | 1088ce662b44SJohannes Berg IEEE80211_FCTL_FROMDS); 1089ce662b44SJohannes Berg } 1090ce662b44SJohannes Berg 1091ce662b44SJohannes Berg skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); 1092ce662b44SJohannes Berg if (!skb) 1093ce662b44SJohannes Berg return; 1094ce662b44SJohannes Berg 1095ce662b44SJohannes Berg skb_reserve(skb, local->hw.extra_tx_headroom); 1096ce662b44SJohannes Berg 1097ce662b44SJohannes Berg nullfunc = (void *) skb_put(skb, size); 1098ce662b44SJohannes Berg nullfunc->frame_control = fc; 1099ce662b44SJohannes Berg nullfunc->duration_id = 0; 1100ce662b44SJohannes Berg memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); 1101ce662b44SJohannes Berg memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); 1102ce662b44SJohannes Berg memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); 1103ce662b44SJohannes Berg 1104ce662b44SJohannes Berg skb->priority = tid; 1105ce662b44SJohannes Berg skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]); 110659b66255SJohannes Berg if (qos) { 1107ce662b44SJohannes Berg nullfunc->qos_ctrl = cpu_to_le16(tid); 1108ce662b44SJohannes Berg 110940b96408SJohannes Berg if (reason == IEEE80211_FRAME_RELEASE_UAPSD) 1110ce662b44SJohannes Berg nullfunc->qos_ctrl |= 1111ce662b44SJohannes Berg cpu_to_le16(IEEE80211_QOS_CTL_EOSP); 1112ce662b44SJohannes Berg } 1113ce662b44SJohannes Berg 1114ce662b44SJohannes Berg info = IEEE80211_SKB_CB(skb); 1115ce662b44SJohannes Berg 1116ce662b44SJohannes Berg /* 1117ce662b44SJohannes Berg * Tell TX path to send this frame even though the 1118ce662b44SJohannes Berg * STA may still remain is PS mode after this frame 1119deeaee19SJohannes Berg * exchange. Also set EOSP to indicate this packet 1120deeaee19SJohannes Berg * ends the poll/service period. 1121ce662b44SJohannes Berg */ 112202f2f1a9SJohannes Berg info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER | 1123deeaee19SJohannes Berg IEEE80211_TX_STATUS_EOSP | 1124ce662b44SJohannes Berg IEEE80211_TX_CTL_REQ_TX_STATUS; 1125ce662b44SJohannes Berg 112640b96408SJohannes Berg drv_allow_buffered_frames(local, sta, BIT(tid), 1, reason, false); 112740b96408SJohannes Berg 112855de908aSJohannes Berg rcu_read_lock(); 112955de908aSJohannes Berg chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); 113055de908aSJohannes Berg if (WARN_ON(!chanctx_conf)) { 113155de908aSJohannes Berg rcu_read_unlock(); 113255de908aSJohannes Berg kfree_skb(skb); 113355de908aSJohannes Berg return; 113455de908aSJohannes Berg } 113555de908aSJohannes Berg 11364bf88530SJohannes Berg ieee80211_xmit(sdata, skb, chanctx_conf->def.chan->band); 113755de908aSJohannes Berg rcu_read_unlock(); 1138ce662b44SJohannes Berg } 1139ce662b44SJohannes Berg 114047086fc5SJohannes Berg static void 114147086fc5SJohannes Berg ieee80211_sta_ps_deliver_response(struct sta_info *sta, 114247086fc5SJohannes Berg int n_frames, u8 ignored_acs, 114347086fc5SJohannes Berg enum ieee80211_frame_release_type reason) 1144af818581SJohannes Berg { 1145af818581SJohannes Berg struct ieee80211_sub_if_data *sdata = sta->sdata; 1146af818581SJohannes Berg struct ieee80211_local *local = sdata->local; 11474049e09aSJohannes Berg bool found = false; 1148948d887dSJohannes Berg bool more_data = false; 1149948d887dSJohannes Berg int ac; 11504049e09aSJohannes Berg unsigned long driver_release_tids = 0; 115147086fc5SJohannes Berg struct sk_buff_head frames; 115247086fc5SJohannes Berg 1153deeaee19SJohannes Berg /* Service or PS-Poll period starts */ 1154c2c98fdeSJohannes Berg set_sta_flag(sta, WLAN_STA_SP); 1155deeaee19SJohannes Berg 115647086fc5SJohannes Berg __skb_queue_head_init(&frames); 1157af818581SJohannes Berg 1158948d887dSJohannes Berg /* 115947086fc5SJohannes Berg * Get response frame(s) and more data bit for it. 1160948d887dSJohannes Berg */ 1161948d887dSJohannes Berg for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 11624049e09aSJohannes Berg unsigned long tids; 11634049e09aSJohannes Berg 116447086fc5SJohannes Berg if (ignored_acs & BIT(ac)) 1165948d887dSJohannes Berg continue; 1166948d887dSJohannes Berg 11674049e09aSJohannes Berg tids = ieee80211_tids_for_ac(ac); 11684049e09aSJohannes Berg 11694049e09aSJohannes Berg if (!found) { 11704049e09aSJohannes Berg driver_release_tids = sta->driver_buffered_tids & tids; 11714049e09aSJohannes Berg if (driver_release_tids) { 11724049e09aSJohannes Berg found = true; 11734049e09aSJohannes Berg } else { 117447086fc5SJohannes Berg struct sk_buff *skb; 117547086fc5SJohannes Berg 117647086fc5SJohannes Berg while (n_frames > 0) { 1177948d887dSJohannes Berg skb = skb_dequeue(&sta->tx_filtered[ac]); 1178948d887dSJohannes Berg if (!skb) { 117947086fc5SJohannes Berg skb = skb_dequeue( 118047086fc5SJohannes Berg &sta->ps_tx_buf[ac]); 1181af818581SJohannes Berg if (skb) 1182af818581SJohannes Berg local->total_ps_buffered--; 1183af818581SJohannes Berg } 118447086fc5SJohannes Berg if (!skb) 118547086fc5SJohannes Berg break; 118647086fc5SJohannes Berg n_frames--; 11874049e09aSJohannes Berg found = true; 118847086fc5SJohannes Berg __skb_queue_tail(&frames, skb); 118947086fc5SJohannes Berg } 1190948d887dSJohannes Berg } 1191948d887dSJohannes Berg 11924049e09aSJohannes Berg /* 11934049e09aSJohannes Berg * If the driver has data on more than one TID then 11944049e09aSJohannes Berg * certainly there's more data if we release just a 11954049e09aSJohannes Berg * single frame now (from a single TID). 11964049e09aSJohannes Berg */ 119747086fc5SJohannes Berg if (reason == IEEE80211_FRAME_RELEASE_PSPOLL && 119847086fc5SJohannes Berg hweight16(driver_release_tids) > 1) { 11994049e09aSJohannes Berg more_data = true; 12004049e09aSJohannes Berg driver_release_tids = 12014049e09aSJohannes Berg BIT(ffs(driver_release_tids) - 1); 12024049e09aSJohannes Berg break; 12034049e09aSJohannes Berg } 12044049e09aSJohannes Berg } 1205948d887dSJohannes Berg 1206948d887dSJohannes Berg if (!skb_queue_empty(&sta->tx_filtered[ac]) || 1207948d887dSJohannes Berg !skb_queue_empty(&sta->ps_tx_buf[ac])) { 1208948d887dSJohannes Berg more_data = true; 1209948d887dSJohannes Berg break; 1210948d887dSJohannes Berg } 1211948d887dSJohannes Berg } 1212af818581SJohannes Berg 12134049e09aSJohannes Berg if (!found) { 1214ce662b44SJohannes Berg int tid; 12154049e09aSJohannes Berg 1216ce662b44SJohannes Berg /* 1217ce662b44SJohannes Berg * For PS-Poll, this can only happen due to a race condition 1218ce662b44SJohannes Berg * when we set the TIM bit and the station notices it, but 1219ce662b44SJohannes Berg * before it can poll for the frame we expire it. 1220ce662b44SJohannes Berg * 1221ce662b44SJohannes Berg * For uAPSD, this is said in the standard (11.2.1.5 h): 1222ce662b44SJohannes Berg * At each unscheduled SP for a non-AP STA, the AP shall 1223ce662b44SJohannes Berg * attempt to transmit at least one MSDU or MMPDU, but no 1224ce662b44SJohannes Berg * more than the value specified in the Max SP Length field 1225ce662b44SJohannes Berg * in the QoS Capability element from delivery-enabled ACs, 1226ce662b44SJohannes Berg * that are destined for the non-AP STA. 1227ce662b44SJohannes Berg * 1228ce662b44SJohannes Berg * Since we have no other MSDU/MMPDU, transmit a QoS null frame. 1229ce662b44SJohannes Berg */ 1230ce662b44SJohannes Berg 1231ce662b44SJohannes Berg /* This will evaluate to 1, 3, 5 or 7. */ 1232ce662b44SJohannes Berg tid = 7 - ((ffs(~ignored_acs) - 1) << 1); 1233ce662b44SJohannes Berg 123440b96408SJohannes Berg ieee80211_send_null_response(sdata, sta, tid, reason); 12354049e09aSJohannes Berg return; 12364049e09aSJohannes Berg } 12374049e09aSJohannes Berg 123847086fc5SJohannes Berg if (!driver_release_tids) { 123947086fc5SJohannes Berg struct sk_buff_head pending; 124047086fc5SJohannes Berg struct sk_buff *skb; 124140b96408SJohannes Berg int num = 0; 124240b96408SJohannes Berg u16 tids = 0; 124347086fc5SJohannes Berg 124447086fc5SJohannes Berg skb_queue_head_init(&pending); 124547086fc5SJohannes Berg 124647086fc5SJohannes Berg while ((skb = __skb_dequeue(&frames))) { 1247af818581SJohannes Berg struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 124847086fc5SJohannes Berg struct ieee80211_hdr *hdr = (void *) skb->data; 124940b96408SJohannes Berg u8 *qoshdr = NULL; 125040b96408SJohannes Berg 125140b96408SJohannes Berg num++; 1252af818581SJohannes Berg 1253af818581SJohannes Berg /* 125447086fc5SJohannes Berg * Tell TX path to send this frame even though the 125547086fc5SJohannes Berg * STA may still remain is PS mode after this frame 125647086fc5SJohannes Berg * exchange. 1257af818581SJohannes Berg */ 125802f2f1a9SJohannes Berg info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER; 1259af818581SJohannes Berg 126047086fc5SJohannes Berg /* 126147086fc5SJohannes Berg * Use MoreData flag to indicate whether there are 126247086fc5SJohannes Berg * more buffered frames for this STA 126347086fc5SJohannes Berg */ 126424b9c373SJanusz.Dziedzic@tieto.com if (more_data || !skb_queue_empty(&frames)) 126547086fc5SJohannes Berg hdr->frame_control |= 126647086fc5SJohannes Berg cpu_to_le16(IEEE80211_FCTL_MOREDATA); 126724b9c373SJanusz.Dziedzic@tieto.com else 126824b9c373SJanusz.Dziedzic@tieto.com hdr->frame_control &= 126924b9c373SJanusz.Dziedzic@tieto.com cpu_to_le16(~IEEE80211_FCTL_MOREDATA); 1270af818581SJohannes Berg 127140b96408SJohannes Berg if (ieee80211_is_data_qos(hdr->frame_control) || 127240b96408SJohannes Berg ieee80211_is_qos_nullfunc(hdr->frame_control)) 127340b96408SJohannes Berg qoshdr = ieee80211_get_qos_ctl(hdr); 127440b96408SJohannes Berg 127552a3f20cSMarco Porsch /* end service period after last frame */ 127652a3f20cSMarco Porsch if (skb_queue_empty(&frames)) { 127740b96408SJohannes Berg if (reason == IEEE80211_FRAME_RELEASE_UAPSD && 127852a3f20cSMarco Porsch qoshdr) 127940b96408SJohannes Berg *qoshdr |= IEEE80211_QOS_CTL_EOSP; 1280deeaee19SJohannes Berg 128147086fc5SJohannes Berg info->flags |= IEEE80211_TX_STATUS_EOSP | 128247086fc5SJohannes Berg IEEE80211_TX_CTL_REQ_TX_STATUS; 128352a3f20cSMarco Porsch } 128447086fc5SJohannes Berg 128540b96408SJohannes Berg if (qoshdr) 128640b96408SJohannes Berg tids |= BIT(*qoshdr & IEEE80211_QOS_CTL_TID_MASK); 128740b96408SJohannes Berg else 128840b96408SJohannes Berg tids |= BIT(0); 128940b96408SJohannes Berg 129047086fc5SJohannes Berg __skb_queue_tail(&pending, skb); 129147086fc5SJohannes Berg } 129247086fc5SJohannes Berg 129340b96408SJohannes Berg drv_allow_buffered_frames(local, sta, tids, num, 129440b96408SJohannes Berg reason, more_data); 129540b96408SJohannes Berg 129647086fc5SJohannes Berg ieee80211_add_pending_skbs(local, &pending); 1297af818581SJohannes Berg 1298c868cb35SJohannes Berg sta_info_recalc_tim(sta); 1299af818581SJohannes Berg } else { 1300af818581SJohannes Berg /* 13014049e09aSJohannes Berg * We need to release a frame that is buffered somewhere in the 13024049e09aSJohannes Berg * driver ... it'll have to handle that. 13034049e09aSJohannes Berg * Note that, as per the comment above, it'll also have to see 13044049e09aSJohannes Berg * if there is more than just one frame on the specific TID that 13054049e09aSJohannes Berg * we're releasing from, and it needs to set the more-data bit 13064049e09aSJohannes Berg * accordingly if we tell it that there's no more data. If we do 13074049e09aSJohannes Berg * tell it there's more data, then of course the more-data bit 13084049e09aSJohannes Berg * needs to be set anyway. 1309af818581SJohannes Berg */ 13104049e09aSJohannes Berg drv_release_buffered_frames(local, sta, driver_release_tids, 131147086fc5SJohannes Berg n_frames, reason, more_data); 13124049e09aSJohannes Berg 13134049e09aSJohannes Berg /* 13144049e09aSJohannes Berg * Note that we don't recalculate the TIM bit here as it would 13154049e09aSJohannes Berg * most likely have no effect at all unless the driver told us 13164049e09aSJohannes Berg * that the TID became empty before returning here from the 13174049e09aSJohannes Berg * release function. 13184049e09aSJohannes Berg * Either way, however, when the driver tells us that the TID 13194049e09aSJohannes Berg * became empty we'll do the TIM recalculation. 13204049e09aSJohannes Berg */ 1321af818581SJohannes Berg } 1322af818581SJohannes Berg } 1323af818581SJohannes Berg 1324af818581SJohannes Berg void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta) 1325af818581SJohannes Berg { 132647086fc5SJohannes Berg u8 ignore_for_response = sta->sta.uapsd_queues; 1327af818581SJohannes Berg 1328af818581SJohannes Berg /* 132947086fc5SJohannes Berg * If all ACs are delivery-enabled then we should reply 133047086fc5SJohannes Berg * from any of them, if only some are enabled we reply 133147086fc5SJohannes Berg * only from the non-enabled ones. 1332af818581SJohannes Berg */ 133347086fc5SJohannes Berg if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1) 133447086fc5SJohannes Berg ignore_for_response = 0; 1335af818581SJohannes Berg 133647086fc5SJohannes Berg ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response, 133747086fc5SJohannes Berg IEEE80211_FRAME_RELEASE_PSPOLL); 1338af818581SJohannes Berg } 133947086fc5SJohannes Berg 134047086fc5SJohannes Berg void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta) 134147086fc5SJohannes Berg { 134247086fc5SJohannes Berg int n_frames = sta->sta.max_sp; 134347086fc5SJohannes Berg u8 delivery_enabled = sta->sta.uapsd_queues; 134447086fc5SJohannes Berg 134547086fc5SJohannes Berg /* 134647086fc5SJohannes Berg * If we ever grow support for TSPEC this might happen if 134747086fc5SJohannes Berg * the TSPEC update from hostapd comes in between a trigger 134847086fc5SJohannes Berg * frame setting WLAN_STA_UAPSD in the RX path and this 134947086fc5SJohannes Berg * actually getting called. 135047086fc5SJohannes Berg */ 135147086fc5SJohannes Berg if (!delivery_enabled) 135247086fc5SJohannes Berg return; 135347086fc5SJohannes Berg 135447086fc5SJohannes Berg switch (sta->sta.max_sp) { 135547086fc5SJohannes Berg case 1: 135647086fc5SJohannes Berg n_frames = 2; 135747086fc5SJohannes Berg break; 135847086fc5SJohannes Berg case 2: 135947086fc5SJohannes Berg n_frames = 4; 136047086fc5SJohannes Berg break; 136147086fc5SJohannes Berg case 3: 136247086fc5SJohannes Berg n_frames = 6; 136347086fc5SJohannes Berg break; 136447086fc5SJohannes Berg case 0: 136547086fc5SJohannes Berg /* XXX: what is a good value? */ 136647086fc5SJohannes Berg n_frames = 8; 136747086fc5SJohannes Berg break; 136847086fc5SJohannes Berg } 136947086fc5SJohannes Berg 137047086fc5SJohannes Berg ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled, 137147086fc5SJohannes Berg IEEE80211_FRAME_RELEASE_UAPSD); 1372af818581SJohannes Berg } 1373af818581SJohannes Berg 1374af818581SJohannes Berg void ieee80211_sta_block_awake(struct ieee80211_hw *hw, 1375af818581SJohannes Berg struct ieee80211_sta *pubsta, bool block) 1376af818581SJohannes Berg { 1377af818581SJohannes Berg struct sta_info *sta = container_of(pubsta, struct sta_info, sta); 1378af818581SJohannes Berg 1379b5878a2dSJohannes Berg trace_api_sta_block_awake(sta->local, pubsta, block); 1380b5878a2dSJohannes Berg 1381af818581SJohannes Berg if (block) 1382c2c98fdeSJohannes Berg set_sta_flag(sta, WLAN_STA_PS_DRIVER); 1383c2c98fdeSJohannes Berg else if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) 1384af818581SJohannes Berg ieee80211_queue_work(hw, &sta->drv_unblock_wk); 1385af818581SJohannes Berg } 1386af818581SJohannes Berg EXPORT_SYMBOL(ieee80211_sta_block_awake); 1387dcf55fb5SFelix Fietkau 138837fbd908SJohannes Berg void ieee80211_sta_eosp_irqsafe(struct ieee80211_sta *pubsta) 138937fbd908SJohannes Berg { 139037fbd908SJohannes Berg struct sta_info *sta = container_of(pubsta, struct sta_info, sta); 139137fbd908SJohannes Berg struct ieee80211_local *local = sta->local; 139237fbd908SJohannes Berg struct sk_buff *skb; 139337fbd908SJohannes Berg struct skb_eosp_msg_data *data; 139437fbd908SJohannes Berg 139537fbd908SJohannes Berg trace_api_eosp(local, pubsta); 139637fbd908SJohannes Berg 139737fbd908SJohannes Berg skb = alloc_skb(0, GFP_ATOMIC); 139837fbd908SJohannes Berg if (!skb) { 139937fbd908SJohannes Berg /* too bad ... but race is better than loss */ 140037fbd908SJohannes Berg clear_sta_flag(sta, WLAN_STA_SP); 140137fbd908SJohannes Berg return; 140237fbd908SJohannes Berg } 140337fbd908SJohannes Berg 140437fbd908SJohannes Berg data = (void *)skb->cb; 140537fbd908SJohannes Berg memcpy(data->sta, pubsta->addr, ETH_ALEN); 140637fbd908SJohannes Berg memcpy(data->iface, sta->sdata->vif.addr, ETH_ALEN); 140737fbd908SJohannes Berg skb->pkt_type = IEEE80211_EOSP_MSG; 140837fbd908SJohannes Berg skb_queue_tail(&local->skb_queue, skb); 140937fbd908SJohannes Berg tasklet_schedule(&local->tasklet); 141037fbd908SJohannes Berg } 141137fbd908SJohannes Berg EXPORT_SYMBOL(ieee80211_sta_eosp_irqsafe); 141237fbd908SJohannes Berg 1413042ec453SJohannes Berg void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta, 1414042ec453SJohannes Berg u8 tid, bool buffered) 1415dcf55fb5SFelix Fietkau { 1416dcf55fb5SFelix Fietkau struct sta_info *sta = container_of(pubsta, struct sta_info, sta); 1417dcf55fb5SFelix Fietkau 14185a306f58SJohannes Berg if (WARN_ON(tid >= IEEE80211_NUM_TIDS)) 1419042ec453SJohannes Berg return; 1420042ec453SJohannes Berg 1421948d887dSJohannes Berg if (buffered) 1422948d887dSJohannes Berg set_bit(tid, &sta->driver_buffered_tids); 1423948d887dSJohannes Berg else 1424948d887dSJohannes Berg clear_bit(tid, &sta->driver_buffered_tids); 1425948d887dSJohannes Berg 1426c868cb35SJohannes Berg sta_info_recalc_tim(sta); 1427dcf55fb5SFelix Fietkau } 1428042ec453SJohannes Berg EXPORT_SYMBOL(ieee80211_sta_set_buffered); 1429d9a7ddb0SJohannes Berg 143083d5cc01SJohannes Berg int sta_info_move_state(struct sta_info *sta, 1431d9a7ddb0SJohannes Berg enum ieee80211_sta_state new_state) 1432d9a7ddb0SJohannes Berg { 14338bf11d8dSJohannes Berg might_sleep(); 1434d9a7ddb0SJohannes Berg 1435d9a7ddb0SJohannes Berg if (sta->sta_state == new_state) 1436d9a7ddb0SJohannes Berg return 0; 1437d9a7ddb0SJohannes Berg 1438f09603a2SJohannes Berg /* check allowed transitions first */ 1439f09603a2SJohannes Berg 1440d9a7ddb0SJohannes Berg switch (new_state) { 1441d9a7ddb0SJohannes Berg case IEEE80211_STA_NONE: 1442f09603a2SJohannes Berg if (sta->sta_state != IEEE80211_STA_AUTH) 1443d9a7ddb0SJohannes Berg return -EINVAL; 1444d9a7ddb0SJohannes Berg break; 1445d9a7ddb0SJohannes Berg case IEEE80211_STA_AUTH: 1446f09603a2SJohannes Berg if (sta->sta_state != IEEE80211_STA_NONE && 1447f09603a2SJohannes Berg sta->sta_state != IEEE80211_STA_ASSOC) 1448d9a7ddb0SJohannes Berg return -EINVAL; 1449d9a7ddb0SJohannes Berg break; 1450d9a7ddb0SJohannes Berg case IEEE80211_STA_ASSOC: 1451f09603a2SJohannes Berg if (sta->sta_state != IEEE80211_STA_AUTH && 1452f09603a2SJohannes Berg sta->sta_state != IEEE80211_STA_AUTHORIZED) 1453d9a7ddb0SJohannes Berg return -EINVAL; 1454d9a7ddb0SJohannes Berg break; 1455d9a7ddb0SJohannes Berg case IEEE80211_STA_AUTHORIZED: 1456f09603a2SJohannes Berg if (sta->sta_state != IEEE80211_STA_ASSOC) 1457d9a7ddb0SJohannes Berg return -EINVAL; 1458d9a7ddb0SJohannes Berg break; 1459d9a7ddb0SJohannes Berg default: 1460d9a7ddb0SJohannes Berg WARN(1, "invalid state %d", new_state); 1461d9a7ddb0SJohannes Berg return -EINVAL; 1462d9a7ddb0SJohannes Berg } 1463d9a7ddb0SJohannes Berg 1464bdcbd8e0SJohannes Berg sta_dbg(sta->sdata, "moving STA %pM to state %d\n", 1465bdcbd8e0SJohannes Berg sta->sta.addr, new_state); 1466f09603a2SJohannes Berg 1467f09603a2SJohannes Berg /* 1468f09603a2SJohannes Berg * notify the driver before the actual changes so it can 1469f09603a2SJohannes Berg * fail the transition 1470f09603a2SJohannes Berg */ 1471f09603a2SJohannes Berg if (test_sta_flag(sta, WLAN_STA_INSERTED)) { 1472f09603a2SJohannes Berg int err = drv_sta_state(sta->local, sta->sdata, sta, 1473f09603a2SJohannes Berg sta->sta_state, new_state); 1474f09603a2SJohannes Berg if (err) 1475f09603a2SJohannes Berg return err; 1476f09603a2SJohannes Berg } 1477f09603a2SJohannes Berg 1478f09603a2SJohannes Berg /* reflect the change in all state variables */ 1479f09603a2SJohannes Berg 1480f09603a2SJohannes Berg switch (new_state) { 1481f09603a2SJohannes Berg case IEEE80211_STA_NONE: 1482f09603a2SJohannes Berg if (sta->sta_state == IEEE80211_STA_AUTH) 1483f09603a2SJohannes Berg clear_bit(WLAN_STA_AUTH, &sta->_flags); 1484f09603a2SJohannes Berg break; 1485f09603a2SJohannes Berg case IEEE80211_STA_AUTH: 1486f09603a2SJohannes Berg if (sta->sta_state == IEEE80211_STA_NONE) 1487f09603a2SJohannes Berg set_bit(WLAN_STA_AUTH, &sta->_flags); 1488f09603a2SJohannes Berg else if (sta->sta_state == IEEE80211_STA_ASSOC) 1489f09603a2SJohannes Berg clear_bit(WLAN_STA_ASSOC, &sta->_flags); 1490f09603a2SJohannes Berg break; 1491f09603a2SJohannes Berg case IEEE80211_STA_ASSOC: 1492f09603a2SJohannes Berg if (sta->sta_state == IEEE80211_STA_AUTH) { 1493f09603a2SJohannes Berg set_bit(WLAN_STA_ASSOC, &sta->_flags); 1494f09603a2SJohannes Berg } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) { 14957e3ed02cSFelix Fietkau if (sta->sdata->vif.type == NL80211_IFTYPE_AP || 14967e3ed02cSFelix Fietkau (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && 14977e3ed02cSFelix Fietkau !sta->sdata->u.vlan.sta)) 14987e3ed02cSFelix Fietkau atomic_dec(&sta->sdata->bss->num_mcast_sta); 1499f09603a2SJohannes Berg clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags); 1500f09603a2SJohannes Berg } 1501f09603a2SJohannes Berg break; 1502f09603a2SJohannes Berg case IEEE80211_STA_AUTHORIZED: 1503f09603a2SJohannes Berg if (sta->sta_state == IEEE80211_STA_ASSOC) { 15047e3ed02cSFelix Fietkau if (sta->sdata->vif.type == NL80211_IFTYPE_AP || 15057e3ed02cSFelix Fietkau (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && 15067e3ed02cSFelix Fietkau !sta->sdata->u.vlan.sta)) 15077e3ed02cSFelix Fietkau atomic_inc(&sta->sdata->bss->num_mcast_sta); 1508f09603a2SJohannes Berg set_bit(WLAN_STA_AUTHORIZED, &sta->_flags); 1509f09603a2SJohannes Berg } 1510f09603a2SJohannes Berg break; 1511f09603a2SJohannes Berg default: 1512f09603a2SJohannes Berg break; 1513f09603a2SJohannes Berg } 1514f09603a2SJohannes Berg 1515d9a7ddb0SJohannes Berg sta->sta_state = new_state; 1516d9a7ddb0SJohannes Berg 1517d9a7ddb0SJohannes Berg return 0; 1518d9a7ddb0SJohannes Berg } 1519