]> Pileus Git - ~andy/linux/blobdiff - net/mac80211/mesh_plink.c
mac80211: consolidate MBSS change notification
[~andy/linux] / net / mac80211 / mesh_plink.c
index 4b274e9c91a5f19c526c9c91d290c9fc574d4098..a4c7a7e98d14238c290e2ac5719024d14572085a 100644 (file)
@@ -41,20 +41,6 @@ static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
                enum ieee80211_self_protected_actioncode action,
                u8 *da, __le16 llid, __le16 plid, __le16 reason);
 
-static inline
-u32 mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
-{
-       atomic_inc(&sdata->u.mesh.estab_plinks);
-       return mesh_accept_plinks_update(sdata);
-}
-
-static inline
-u32 mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
-{
-       atomic_dec(&sdata->u.mesh.estab_plinks);
-       return mesh_accept_plinks_update(sdata);
-}
-
 /**
  * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
  *
@@ -70,27 +56,63 @@ static inline void mesh_plink_fsm_restart(struct sta_info *sta)
 }
 
 /*
- * Allocate mesh sta entry and insert into station table
+ * mesh_set_short_slot_time - enable / disable ERP short slot time.
+ *
+ * The standard indirectly mandates mesh STAs to turn off short slot time by
+ * disallowing advertising this (802.11-2012 8.4.1.4), but that doesn't mean we
+ * can't be sneaky about it. Enable short slot time if all mesh STAs in the
+ * MBSS support ERP rates.
+ *
+ * Returns BSS_CHANGED_ERP_SLOT or 0 for no change.
  */
-static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
-                                        u8 *hw_addr)
+static u32 mesh_set_short_slot_time(struct ieee80211_sub_if_data *sdata)
 {
+       struct ieee80211_local *local = sdata->local;
+       enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
+       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
        struct sta_info *sta;
+       u32 erp_rates = 0, changed = 0;
+       int i;
+       bool short_slot = false;
 
-       if (sdata->local->num_sta >= MESH_MAX_PLINKS)
-               return NULL;
+       if (band == IEEE80211_BAND_5GHZ) {
+               /* (IEEE 802.11-2012 19.4.5) */
+               short_slot = true;
+               goto out;
+       } else if (band != IEEE80211_BAND_2GHZ ||
+                  (band == IEEE80211_BAND_2GHZ &&
+                   local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
+               goto out;
 
-       sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
-       if (!sta)
-               return NULL;
+       for (i = 0; i < sband->n_bitrates; i++)
+               if (sband->bitrates[i].flags & IEEE80211_RATE_ERP_G)
+                       erp_rates |= BIT(i);
 
-       sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
-       sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
-       sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
+       if (!erp_rates)
+               goto out;
 
-       set_sta_flag(sta, WLAN_STA_WME);
+       rcu_read_lock();
+       list_for_each_entry_rcu(sta, &local->sta_list, list) {
+               if (sdata != sta->sdata ||
+                   sta->plink_state != NL80211_PLINK_ESTAB)
+                       continue;
 
-       return sta;
+               short_slot = false;
+               if (erp_rates & sta->sta.supp_rates[band])
+                       short_slot = true;
+                else
+                       break;
+       }
+       rcu_read_unlock();
+
+out:
+       if (sdata->vif.bss_conf.use_short_slot != short_slot) {
+               sdata->vif.bss_conf.use_short_slot = short_slot;
+               changed = BSS_CHANGED_ERP_SLOT;
+               mpl_dbg(sdata, "mesh_plink %pM: ERP short slot time %d\n",
+                       sdata->vif.addr, short_slot);
+       }
+       return changed;
 }
 
 /**
@@ -179,6 +201,9 @@ static u32 __mesh_plink_deactivate(struct sta_info *sta)
        sta->plink_state = NL80211_PLINK_BLOCKED;
        mesh_path_flush_by_nexthop(sta);
 
+       ieee80211_mps_sta_status_update(sta);
+       changed |= ieee80211_mps_local_status_update(sdata);
+
        return changed;
 }
 
@@ -189,7 +214,7 @@ static u32 __mesh_plink_deactivate(struct sta_info *sta)
  *
  * All mesh paths with this peer as next hop will be flushed
  */
-void mesh_plink_deactivate(struct sta_info *sta)
+u32 mesh_plink_deactivate(struct sta_info *sta)
 {
        struct ieee80211_sub_if_data *sdata = sta->sdata;
        u32 changed;
@@ -202,7 +227,7 @@ void mesh_plink_deactivate(struct sta_info *sta)
                            sta->reason);
        spin_unlock_bh(&sta->lock);
 
-       ieee80211_bss_info_change_notify(sdata, changed);
+       return changed;
 }
 
 static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
@@ -323,53 +348,27 @@ free:
        return err;
 }
 
-/**
- * mesh_peer_init - initialize new mesh peer and return resulting sta_info
- *
- * @sdata: local meshif
- * @addr: peer's address
- * @elems: IEs from beacon or mesh peering frame
- *
- * call under RCU
- */
-static struct sta_info *mesh_peer_init(struct ieee80211_sub_if_data *sdata,
-                                      u8 *addr,
-                                      struct ieee802_11_elems *elems)
+static void mesh_sta_info_init(struct ieee80211_sub_if_data *sdata,
+                              struct sta_info *sta,
+                              struct ieee802_11_elems *elems, bool insert)
 {
        struct ieee80211_local *local = sdata->local;
        enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
        struct ieee80211_supported_band *sband;
-       u32 rates, basic_rates = 0;
-       struct sta_info *sta;
-       bool insert = false;
+       u32 rates, basic_rates = 0, changed = 0;
 
        sband = local->hw.wiphy->bands[band];
        rates = ieee80211_sta_get_rates(local, elems, band, &basic_rates);
 
-       sta = sta_info_get(sdata, addr);
-       if (!sta) {
-               /* Userspace handles peer allocation when security is enabled */
-               if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED) {
-                       cfg80211_notify_new_peer_candidate(sdata->dev, addr,
-                                                          elems->ie_start,
-                                                          elems->total_len,
-                                                          GFP_ATOMIC);
-                       return NULL;
-               }
-
-               sta = mesh_plink_alloc(sdata, addr);
-               if (!sta)
-                       return NULL;
-               insert = true;
-       }
-
        spin_lock_bh(&sta->lock);
        sta->last_rx = jiffies;
-       if (sta->plink_state == NL80211_PLINK_ESTAB) {
-               spin_unlock_bh(&sta->lock);
-               return sta;
-       }
 
+       /* rates and capabilities don't change during peering */
+       if (sta->plink_state == NL80211_PLINK_ESTAB)
+               goto out;
+
+       if (sta->sta.supp_rates[band] != rates)
+               changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
        sta->sta.supp_rates[band] = rates;
        if (elems->ht_cap_elem &&
            sdata->vif.bss_conf.chandef.width != NL80211_CHAN_WIDTH_20_NOHT)
@@ -388,27 +387,116 @@ static struct sta_info *mesh_peer_init(struct ieee80211_sub_if_data *sdata,
                                            ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
                ieee80211_ht_oper_to_chandef(sdata->vif.bss_conf.chandef.chan,
                                             elems->ht_operation, &chandef);
+               if (sta->ch_width != chandef.width)
+                       changed |= IEEE80211_RC_BW_CHANGED;
                sta->ch_width = chandef.width;
        }
 
        if (insert)
                rate_control_rate_init(sta);
+       else
+               rate_control_rate_update(local, sband, sta, changed);
+out:
        spin_unlock_bh(&sta->lock);
+}
+
+static struct sta_info *
+__mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *hw_addr)
+{
+       struct sta_info *sta;
+
+       if (sdata->local->num_sta >= MESH_MAX_PLINKS)
+               return NULL;
 
-       if (insert && sta_info_insert(sta))
+       sta = sta_info_alloc(sdata, hw_addr, GFP_KERNEL);
+       if (!sta)
                return NULL;
 
+       sta->plink_state = NL80211_PLINK_LISTEN;
+       init_timer(&sta->plink_timer);
+
+       sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
+       sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
+       sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
+
+       set_sta_flag(sta, WLAN_STA_WME);
+
        return sta;
 }
 
+static struct sta_info *
+mesh_sta_info_alloc(struct ieee80211_sub_if_data *sdata, u8 *addr,
+                   struct ieee802_11_elems *elems)
+{
+       struct sta_info *sta = NULL;
+
+       /* Userspace handles peer allocation when security is enabled */
+       if (sdata->u.mesh.security & IEEE80211_MESH_SEC_AUTHED)
+               cfg80211_notify_new_peer_candidate(sdata->dev, addr,
+                                                  elems->ie_start,
+                                                  elems->total_len,
+                                                  GFP_KERNEL);
+       else
+               sta = __mesh_sta_info_alloc(sdata, addr);
+
+       return sta;
+}
+
+/*
+ * mesh_sta_info_get - return mesh sta info entry for @addr.
+ *
+ * @sdata: local meshif
+ * @addr: peer's address
+ * @elems: IEs from beacon or mesh peering frame.
+ *
+ * Return existing or newly allocated sta_info under RCU read lock.
+ * (re)initialize with given IEs.
+ */
+static struct sta_info *
+mesh_sta_info_get(struct ieee80211_sub_if_data *sdata,
+                 u8 *addr, struct ieee802_11_elems *elems) __acquires(RCU)
+{
+       struct sta_info *sta = NULL;
+
+       rcu_read_lock();
+       sta = sta_info_get(sdata, addr);
+       if (sta) {
+               mesh_sta_info_init(sdata, sta, elems, false);
+       } else {
+               rcu_read_unlock();
+               /* can't run atomic */
+               sta = mesh_sta_info_alloc(sdata, addr, elems);
+               if (!sta) {
+                       rcu_read_lock();
+                       return NULL;
+               }
+
+               mesh_sta_info_init(sdata, sta, elems, true);
+
+               if (sta_info_insert_rcu(sta))
+                       return NULL;
+       }
+
+       return sta;
+}
+
+/*
+ * mesh_neighbour_update - update or initialize new mesh neighbor.
+ *
+ * @sdata: local meshif
+ * @addr: peer's address
+ * @elems: IEs from beacon or mesh peering frame
+ *
+ * Initiates peering if appropriate.
+ */
 void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
                           u8 *hw_addr,
                           struct ieee802_11_elems *elems)
 {
        struct sta_info *sta;
+       u32 changed = 0;
 
-       rcu_read_lock();
-       sta = mesh_peer_init(sdata, hw_addr, elems);
+       sta = mesh_sta_info_get(sdata, hw_addr, elems);
        if (!sta)
                goto out;
 
@@ -417,10 +505,12 @@ void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,
            sdata->u.mesh.accepting_plinks &&
            sdata->u.mesh.mshcfg.auto_open_plinks &&
            rssi_threshold_check(sta, sdata))
-               mesh_plink_open(sta);
+               changed = mesh_plink_open(sta);
 
+       ieee80211_mps_frame_release(sta, elems);
 out:
        rcu_read_unlock();
+       ieee80211_bss_info_change_notify(sdata, changed);
 }
 
 static void mesh_plink_timer(unsigned long data)
@@ -504,6 +594,13 @@ static void mesh_plink_timer(unsigned long data)
 #ifdef CONFIG_PM
 void mesh_plink_quiesce(struct sta_info *sta)
 {
+       if (!ieee80211_vif_is_mesh(&sta->sdata->vif))
+               return;
+
+       /* no kernel mesh sta timers have been initialized */
+       if (sta->sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
+               return;
+
        if (del_timer_sync(&sta->plink_timer))
                sta->plink_timer_was_running = true;
 }
@@ -526,13 +623,14 @@ static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
        add_timer(&sta->plink_timer);
 }
 
-int mesh_plink_open(struct sta_info *sta)
+u32 mesh_plink_open(struct sta_info *sta)
 {
        __le16 llid;
        struct ieee80211_sub_if_data *sdata = sta->sdata;
+       u32 changed;
 
        if (!test_sta_flag(sta, WLAN_STA_AUTH))
-               return -EPERM;
+               return 0;
 
        spin_lock_bh(&sta->lock);
        get_random_bytes(&llid, 2);
@@ -540,7 +638,7 @@ int mesh_plink_open(struct sta_info *sta)
        if (sta->plink_state != NL80211_PLINK_LISTEN &&
            sta->plink_state != NL80211_PLINK_BLOCKED) {
                spin_unlock_bh(&sta->lock);
-               return -EBUSY;
+               return 0;
        }
        sta->plink_state = NL80211_PLINK_OPN_SNT;
        mesh_plink_timer_set(sta, sdata->u.mesh.mshcfg.dot11MeshRetryTimeout);
@@ -549,13 +647,16 @@ int mesh_plink_open(struct sta_info *sta)
                "Mesh plink: starting establishment with %pM\n",
                sta->sta.addr);
 
-       return mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
-                                  sta->sta.addr, llid, 0, 0);
+       /* set the non-peer mode to active during peering */
+       changed = ieee80211_mps_local_status_update(sdata);
+
+       mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN,
+                           sta->sta.addr, llid, 0, 0);
+       return changed;
 }
 
-void mesh_plink_block(struct sta_info *sta)
+u32 mesh_plink_block(struct sta_info *sta)
 {
-       struct ieee80211_sub_if_data *sdata = sta->sdata;
        u32 changed;
 
        spin_lock_bh(&sta->lock);
@@ -563,7 +664,7 @@ void mesh_plink_block(struct sta_info *sta)
        sta->plink_state = NL80211_PLINK_BLOCKED;
        spin_unlock_bh(&sta->lock);
 
-       ieee80211_bss_info_change_notify(sdata, changed);
+       return changed;
 }
 
 
@@ -646,6 +747,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
            (ftype == WLAN_SP_MESH_PEERING_CLOSE && ie_len == 8))
                memcpy(&llid, PLINK_GET_PLID(elems.peering), 2);
 
+       /* WARNING: Only for sta pointer, is dropped & re-acquired */
        rcu_read_lock();
 
        sta = sta_info_get(sdata, mgmt->sa);
@@ -749,8 +851,9 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
        }
 
        if (event == OPN_ACPT) {
+               rcu_read_unlock();
                /* allocate sta entry if necessary and update info */
-               sta = mesh_peer_init(sdata, mgmt->sa, &elems);
+               sta = mesh_sta_info_get(sdata, mgmt->sa, &elems);
                if (!sta) {
                        mpl_dbg(sdata, "Mesh plink: failed to init peer!\n");
                        rcu_read_unlock();
@@ -780,6 +883,10 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
                        sta->llid = llid;
                        mesh_plink_timer_set(sta,
                                             mshcfg->dot11MeshRetryTimeout);
+
+                       /* set the non-peer mode to active during peering */
+                       changed |= ieee80211_mps_local_status_update(sdata);
+
                        spin_unlock_bh(&sta->lock);
                        mesh_plink_frame_tx(sdata,
                                            WLAN_SP_MESH_PEERING_OPEN,
@@ -870,8 +977,12 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
                        spin_unlock_bh(&sta->lock);
                        changed |= mesh_plink_inc_estab_count(sdata);
                        changed |= mesh_set_ht_prot_mode(sdata);
+                       changed |= mesh_set_short_slot_time(sdata);
                        mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n",
                                sta->sta.addr);
+                       ieee80211_mps_sta_status_update(sta);
+                       changed |= ieee80211_mps_set_sta_local_pm(sta,
+                                                      mshcfg->power_mode);
                        break;
                default:
                        spin_unlock_bh(&sta->lock);
@@ -905,11 +1016,15 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
                        spin_unlock_bh(&sta->lock);
                        changed |= mesh_plink_inc_estab_count(sdata);
                        changed |= mesh_set_ht_prot_mode(sdata);
+                       changed |= mesh_set_short_slot_time(sdata);
                        mpl_dbg(sdata, "Mesh plink with %pM ESTABLISHED\n",
                                sta->sta.addr);
                        mesh_plink_frame_tx(sdata,
                                            WLAN_SP_MESH_PEERING_CONFIRM,
                                            sta->sta.addr, llid, plid, 0);
+                       ieee80211_mps_sta_status_update(sta);
+                       changed |= ieee80211_mps_set_sta_local_pm(sta,
+                                                       mshcfg->power_mode);
                        break;
                default:
                        spin_unlock_bh(&sta->lock);
@@ -928,6 +1043,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
                        mod_plink_timer(sta, mshcfg->dot11MeshHoldingTimeout);
                        spin_unlock_bh(&sta->lock);
                        changed |= mesh_set_ht_prot_mode(sdata);
+                       changed |= mesh_set_short_slot_time(sdata);
                        mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_CLOSE,
                                            sta->sta.addr, llid, plid, reason);
                        break;