mac80211: improve/fix mlme messages
[safe/jmp/linux-2.6] / net / mac80211 / mesh_hwmp.c
index 501c783..e12a786 100644 (file)
@@ -58,7 +58,6 @@ static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
 #define PERR_IE_DST_ADDR(x)    (x + 2)
 #define PERR_IE_DST_DSN(x)     u32_field_get(x, 8, 0);
 
-#define TU_TO_EXP_TIME(x) (jiffies + msecs_to_jiffies(x * 1024 / 1000))
 #define MSEC_TO_TU(x) (x*1000/1024)
 #define DSN_GT(x, y) ((long) (y) - (long) (x) < 0)
 #define DSN_LT(x, y) ((long) (x) - (long) (y) < 0)
@@ -149,7 +148,7 @@ static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
        pos += ETH_ALEN;
        memcpy(pos, &dst_dsn, 4);
 
-       ieee80211_tx_skb(sdata, skb, 0);
+       ieee80211_tx_skb(sdata, skb, 1);
        return 0;
 }
 
@@ -198,10 +197,28 @@ int mesh_path_error_tx(u8 *dst, __le32 dst_dsn, u8 *ra,
        pos += ETH_ALEN;
        memcpy(pos, &dst_dsn, 4);
 
-       ieee80211_tx_skb(sdata, skb, 0);
+       ieee80211_tx_skb(sdata, skb, 1);
        return 0;
 }
 
+void ieee80211s_update_metric(struct ieee80211_local *local,
+               struct sta_info *stainfo, struct sk_buff *skb)
+{
+       struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+       int failed;
+
+       if (!ieee80211_is_data(hdr->frame_control))
+               return;
+
+       failed = !(txinfo->flags & IEEE80211_TX_STAT_ACK);
+
+       /* moving average, scaled to 100 */
+       stainfo->fail_avg = ((80 * stainfo->fail_avg + 5) / 100 + 20 * failed);
+       if (stainfo->fail_avg > 95)
+               mesh_plink_broken(stainfo);
+}
+
 static u32 airtime_link_metric_get(struct ieee80211_local *local,
                                   struct sta_info *sta)
 {
@@ -218,12 +235,16 @@ static u32 airtime_link_metric_get(struct ieee80211_local *local,
 
        if (sta->fail_avg >= 100)
                return MAX_METRIC;
+
+       if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
+               return MAX_METRIC;
+
        err = (sta->fail_avg << ARITH_SHIFT) / 100;
 
        /* bitrate is in units of 100 Kbps, while we need rate in units of
         * 1Mbps. This will be corrected on tx_time computation.
         */
-       rate = sband->bitrates[sta->last_txrate_idx].bitrate;
+       rate = sband->bitrates[sta->last_tx_rate.idx].bitrate;
        tx_time = (device_constant + 10 * test_frame_len / rate);
        estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
        result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ;
@@ -394,7 +415,8 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
 
 static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
                                    struct ieee80211_mgmt *mgmt,
-                                   u8 *preq_elem, u32 metric) {
+                                   u8 *preq_elem, u32 metric)
+{
        struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
        struct mesh_path *mpath;
        u8 *dst_addr, *orig_addr;
@@ -427,7 +449,7 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
                        if ((!(mpath->flags & MESH_PATH_DSN_VALID)) ||
                                        DSN_LT(mpath->dsn, dst_dsn)) {
                                mpath->dsn = dst_dsn;
-                               mpath->flags &= MESH_PATH_DSN_VALID;
+                               mpath->flags |= MESH_PATH_DSN_VALID;
                        } else if ((!(dst_flags & MP_F_DO)) &&
                                        (mpath->flags & MESH_PATH_ACTIVE)) {
                                reply = true;
@@ -475,6 +497,7 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
                                hopcount, ttl, cpu_to_le32(lifetime),
                                cpu_to_le32(metric), cpu_to_le32(preq_id),
                                sdata);
+               ifmsh->mshstats.fwded_mcast++;
                ifmsh->mshstats.fwded_frames++;
        }
 }
@@ -533,6 +556,8 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
                cpu_to_le32(lifetime), cpu_to_le32(metric),
                0, sdata);
        rcu_read_unlock();
+
+       sdata->u.mesh.mshstats.fwded_unicast++;
        sdata->u.mesh.mshstats.fwded_frames++;
        return;
 
@@ -634,7 +659,7 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
        struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
        struct mesh_preq_queue *preq_node;
 
-       preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_KERNEL);
+       preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_ATOMIC);
        if (!preq_node) {
                printk(KERN_DEBUG "Mesh HWMP: could not allocate PREQ node\n");
                return;
@@ -657,14 +682,14 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
        spin_unlock(&ifmsh->mesh_preq_queue_lock);
 
        if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata)))
-               queue_work(sdata->local->hw.workqueue, &ifmsh->work);
+               ieee80211_queue_work(&sdata->local->hw, &ifmsh->work);
 
        else if (time_before(jiffies, ifmsh->last_preq)) {
                /* avoid long wait if did not send preqs for a long time
                 * and jiffies wrapped around
                 */
                ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
-               queue_work(sdata->local->hw.workqueue, &ifmsh->work);
+               ieee80211_queue_work(&sdata->local->hw, &ifmsh->work);
        } else
                mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq +
                                                min_preq_int_jiff(sdata));
@@ -683,11 +708,11 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
        u8 ttl, dst_flags;
        u32 lifetime;
 
-       spin_lock(&ifmsh->mesh_preq_queue_lock);
+       spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
        if (!ifmsh->preq_queue_len ||
                time_before(jiffies, ifmsh->last_preq +
                                min_preq_int_jiff(sdata))) {
-               spin_unlock(&ifmsh->mesh_preq_queue_lock);
+               spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
                return;
        }
 
@@ -695,7 +720,7 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
                        struct mesh_preq_queue, list);
        list_del(&preq_node->list);
        --ifmsh->preq_queue_len;
-       spin_unlock(&ifmsh->mesh_preq_queue_lock);
+       spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
 
        rcu_read_lock();
        mpath = mesh_path_lookup(preq_node->dst, sdata);
@@ -755,11 +780,10 @@ enddiscovery:
 }
 
 /**
- * ieee80211s_lookup_nexthop - put the appropriate next hop on a mesh frame
+ * mesh_nexthop_lookup - put the appropriate next hop on a mesh frame
  *
  * @skb: 802.11 frame to be sent
  * @sdata: network subif the frame will be sent through
- * @fwd_frame: true if this frame was originally from a different host
  *
  * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is
  * found, the function will start a path discovery and queue the frame so it is
@@ -782,7 +806,6 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
                mesh_path_add(dst_addr, sdata);
                mpath = mesh_path_lookup(dst_addr, sdata);
                if (!mpath) {
-                       dev_kfree_skb(skb);
                        sdata->u.mesh.mshstats.dropped_frames_no_route++;
                        err = -ENOSPC;
                        goto endlookup;
@@ -790,7 +813,7 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
        }
 
        if (mpath->flags & MESH_PATH_ACTIVE) {
-               if (time_after(jiffies, mpath->exp_time -
+               if (time_after(jiffies, mpath->exp_time +
                        msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time))
                                && !memcmp(sdata->dev->dev_addr, hdr->addr4,
                                           ETH_ALEN)
@@ -802,17 +825,17 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
                memcpy(hdr->addr1, mpath->next_hop->sta.addr,
                                ETH_ALEN);
        } else {
+               struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
                if (!(mpath->flags & MESH_PATH_RESOLVING)) {
                        /* Start discovery only if it is not running yet */
                        mesh_queue_preq(mpath, PREQ_Q_F_START);
                }
 
                if (skb_queue_len(&mpath->frame_queue) >=
-                               MESH_FRAME_QUEUE_LEN) {
-                       skb_to_free = mpath->frame_queue.next;
-                       skb_unlink(skb_to_free, &mpath->frame_queue);
-               }
+                               MESH_FRAME_QUEUE_LEN)
+                       skb_to_free = skb_dequeue(&mpath->frame_queue);
 
+               info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
                skb_queue_tail(&mpath->frame_queue, skb);
                if (skb_to_free)
                        mesh_path_discard_frame(skb_to_free, sdata);
@@ -834,8 +857,14 @@ void mesh_path_timer(unsigned long data)
        mpath = rcu_dereference(mpath);
        if (!mpath)
                goto endmpathtimer;
-       spin_lock_bh(&mpath->state_lock);
        sdata = mpath->sdata;
+
+       if (sdata->local->quiescing) {
+               rcu_read_unlock();
+               return;
+       }
+
+       spin_lock_bh(&mpath->state_lock);
        if (mpath->flags & MESH_PATH_RESOLVED ||
                        (!(mpath->flags & MESH_PATH_RESOLVING)))
                mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED);