mac80211: add MAC80211_VERBOSE_MHWMP_DEBUG
[safe/jmp/linux-2.6] / net / mac80211 / mesh.c
index 8a1fcae..63427d9 100644 (file)
 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
 
-#define PP_OFFSET      1               /* Path Selection Protocol */
-#define PM_OFFSET      5               /* Path Selection Metric   */
-#define CC_OFFSET      9               /* Congestion Control Mode */
-#define CAPAB_OFFSET 17
-#define ACCEPT_PLINKS 0x80
+#define MESHCONF_PP_OFFSET     0               /* Path Selection Protocol */
+#define MESHCONF_PM_OFFSET     1               /* Path Selection Metric   */
+#define MESHCONF_CC_OFFSET     2               /* Congestion Control Mode */
+#define MESHCONF_SP_OFFSET     3               /* Synchronization Protocol */
+#define MESHCONF_AUTH_OFFSET   4               /* Authentication Protocol */
+#define MESHCONF_CAPAB_OFFSET  6
+#define MESHCONF_CAPAB_ACCEPT_PLINKS 0x01
+#define MESHCONF_CAPAB_FORWARDING    0x08
+
+#define TMR_RUNNING_HK 0
+#define TMR_RUNNING_MP 1
 
 int mesh_allocated;
 static struct kmem_cache *rm_cache;
@@ -44,8 +50,14 @@ static void ieee80211_mesh_housekeeping_timer(unsigned long data)
        struct ieee80211_local *local = sdata->local;
        struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
 
-       ifmsh->housekeeping = true;
-       queue_work(local->hw.workqueue, &ifmsh->work);
+       set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
+
+       if (local->quiescing) {
+               set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
+               return;
+       }
+
+       ieee80211_queue_work(&local->hw, &ifmsh->work);
 }
 
 /**
@@ -73,9 +85,12 @@ bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_dat
         */
        if (ifmsh->mesh_id_len == ie->mesh_id_len &&
                memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
-               memcmp(ifmsh->mesh_pp_id, ie->mesh_config + PP_OFFSET, 4) == 0 &&
-               memcmp(ifmsh->mesh_pm_id, ie->mesh_config + PM_OFFSET, 4) == 0 &&
-               memcmp(ifmsh->mesh_cc_id, ie->mesh_config + CC_OFFSET, 4) == 0)
+               (ifmsh->mesh_pp_id == *(ie->mesh_config + MESHCONF_PP_OFFSET))&&
+               (ifmsh->mesh_pm_id == *(ie->mesh_config + MESHCONF_PM_OFFSET))&&
+               (ifmsh->mesh_cc_id == *(ie->mesh_config + MESHCONF_CC_OFFSET))&&
+               (ifmsh->mesh_sp_id == *(ie->mesh_config + MESHCONF_SP_OFFSET))&&
+               (ifmsh->mesh_auth_id == *(ie->mesh_config +
+                   MESHCONF_AUTH_OFFSET)))
                return true;
 
        return false;
@@ -88,7 +103,8 @@ bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_dat
  */
 bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie)
 {
-       return (*(ie->mesh_config + CAPAB_OFFSET) & ACCEPT_PLINKS) != 0;
+       return (*(ie->mesh_config + MESHCONF_CAPAB_OFFSET) &
+           MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
 }
 
 /**
@@ -114,11 +130,11 @@ void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
 
 void mesh_ids_set_default(struct ieee80211_if_mesh *sta)
 {
-       u8 def_id[4] = {0x00, 0x0F, 0xAC, 0xff};
-
-       memcpy(sta->mesh_pp_id, def_id, 4);
-       memcpy(sta->mesh_pm_id, def_id, 4);
-       memcpy(sta->mesh_cc_id, def_id, 4);
+       sta->mesh_pp_id = 0;    /* HWMP */
+       sta->mesh_pm_id = 0;    /* Airtime */
+       sta->mesh_cc_id = 0;    /* Disabled */
+       sta->mesh_sp_id = 0;    /* Neighbor Offset */
+       sta->mesh_auth_id = 0;  /* Disabled */
 }
 
 int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
@@ -207,6 +223,7 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
        struct ieee80211_supported_band *sband;
        u8 *pos;
        int len, i, rate;
+       u8 neighbors;
 
        sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
        len = sband->n_bitrates;
@@ -236,33 +253,36 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
        if (sdata->u.mesh.mesh_id_len)
                memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len);
 
-       pos = skb_put(skb, 21);
+       pos = skb_put(skb, 2 + IEEE80211_MESH_CONFIG_LEN);
        *pos++ = WLAN_EID_MESH_CONFIG;
        *pos++ = IEEE80211_MESH_CONFIG_LEN;
-       /* Version */
-       *pos++ = 1;
 
        /* Active path selection protocol ID */
-       memcpy(pos, sdata->u.mesh.mesh_pp_id, 4);
-       pos += 4;
+       *pos++ = sdata->u.mesh.mesh_pp_id;
 
        /* Active path selection metric ID   */
-       memcpy(pos, sdata->u.mesh.mesh_pm_id, 4);
-       pos += 4;
+       *pos++ = sdata->u.mesh.mesh_pm_id;
 
        /* Congestion control mode identifier */
-       memcpy(pos, sdata->u.mesh.mesh_cc_id, 4);
-       pos += 4;
+       *pos++ = sdata->u.mesh.mesh_cc_id;
 
-       /* Channel precedence:
-        * Not running simple channel unification protocol
-        */
-       memset(pos, 0x00, 4);
-       pos += 4;
+       /* Synchronization protocol identifier */
+       *pos++ = sdata->u.mesh.mesh_sp_id;
+
+       /* Authentication Protocol identifier */
+       *pos++ = sdata->u.mesh.mesh_auth_id;
+
+       /* Mesh Formation Info - number of neighbors */
+       neighbors = atomic_read(&sdata->u.mesh.mshstats.estab_plinks);
+       /* Number of neighbor mesh STAs or 15 whichever is smaller */
+       neighbors = (neighbors > 15) ? 15 : neighbors;
+       *pos++ = neighbors << 1;
 
        /* Mesh capability */
        sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata);
-       *pos++ = sdata->u.mesh.accepting_plinks ? ACCEPT_PLINKS : 0x00;
+       *pos = MESHCONF_CAPAB_FORWARDING;
+       *pos++ |= sdata->u.mesh.accepting_plinks ?
+           MESHCONF_CAPAB_ACCEPT_PLINKS : 0x00;
        *pos++ = 0x00;
 
        return;
@@ -275,16 +295,6 @@ u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata, struct mesh_t
                & tbl->hash_mask;
 }
 
-u8 mesh_id_hash(u8 *mesh_id, int mesh_id_len)
-{
-       if (!mesh_id_len)
-               return 1;
-       else if (mesh_id_len == 1)
-               return (u8) mesh_id[0];
-       else
-               return (u8) (mesh_id[0] + 2 * mesh_id[1]);
-}
-
 struct mesh_table *mesh_table_alloc(int size_order)
 {
        int i;
@@ -321,30 +331,6 @@ struct mesh_table *mesh_table_alloc(int size_order)
        return newtbl;
 }
 
-static void __mesh_table_free(struct mesh_table *tbl)
-{
-       kfree(tbl->hash_buckets);
-       kfree(tbl->hashwlock);
-       kfree(tbl);
-}
-
-void mesh_table_free(struct mesh_table *tbl, bool free_leafs)
-{
-       struct hlist_head *mesh_hash;
-       struct hlist_node *p, *q;
-       int i;
-
-       mesh_hash = tbl->hash_buckets;
-       for (i = 0; i <= tbl->hash_mask; i++) {
-               spin_lock(&tbl->hashwlock[i]);
-               hlist_for_each_safe(p, q, &mesh_hash[i]) {
-                       tbl->free_node(p, free_leafs);
-                       atomic_dec(&tbl->entries);
-               }
-               spin_unlock(&tbl->hashwlock[i]);
-       }
-       __mesh_table_free(tbl);
-}
 
 static void ieee80211_mesh_path_timer(unsigned long data)
 {
@@ -353,63 +339,84 @@ static void ieee80211_mesh_path_timer(unsigned long data)
        struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
        struct ieee80211_local *local = sdata->local;
 
-       queue_work(local->hw.workqueue, &ifmsh->work);
-}
-
-struct mesh_table *mesh_table_grow(struct mesh_table *tbl)
-{
-       struct mesh_table *newtbl;
-       struct hlist_head *oldhash;
-       struct hlist_node *p, *q;
-       int i;
-
-       if (atomic_read(&tbl->entries)
-                       < tbl->mean_chain_len * (tbl->hash_mask + 1))
-               goto endgrow;
-
-       newtbl = mesh_table_alloc(tbl->size_order + 1);
-       if (!newtbl)
-               goto endgrow;
-
-       newtbl->free_node = tbl->free_node;
-       newtbl->mean_chain_len = tbl->mean_chain_len;
-       newtbl->copy_node = tbl->copy_node;
-       atomic_set(&newtbl->entries, atomic_read(&tbl->entries));
-
-       oldhash = tbl->hash_buckets;
-       for (i = 0; i <= tbl->hash_mask; i++)
-               hlist_for_each(p, &oldhash[i])
-                       if (tbl->copy_node(p, newtbl) < 0)
-                               goto errcopy;
+       if (local->quiescing) {
+               set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
+               return;
+       }
 
-       return newtbl;
+       ieee80211_queue_work(&local->hw, &ifmsh->work);
+}
 
-errcopy:
-       for (i = 0; i <= newtbl->hash_mask; i++) {
-               hlist_for_each_safe(p, q, &newtbl->hash_buckets[i])
-                       tbl->free_node(p, 0);
+/**
+ * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
+ * @hdr:       802.11 frame header
+ * @fc:                frame control field
+ * @meshda:    destination address in the mesh
+ * @meshsa:    source address address in the mesh.  Same as TA, as frame is
+ *              locally originated.
+ *
+ * Return the length of the 802.11 (does not include a mesh control header)
+ */
+int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc, char
+               *meshda, char *meshsa) {
+       if (is_multicast_ether_addr(meshda)) {
+               *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
+               /* DA TA SA */
+               memcpy(hdr->addr1, meshda, ETH_ALEN);
+               memcpy(hdr->addr2, meshsa, ETH_ALEN);
+               memcpy(hdr->addr3, meshsa, ETH_ALEN);
+               return 24;
+       } else {
+               *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
+                               IEEE80211_FCTL_TODS);
+               /* RA TA DA SA */
+               memset(hdr->addr1, 0, ETH_ALEN);   /* RA is resolved later */
+               memcpy(hdr->addr2, meshsa, ETH_ALEN);
+               memcpy(hdr->addr3, meshda, ETH_ALEN);
+               memcpy(hdr->addr4, meshsa, ETH_ALEN);
+               return 30;
        }
-       __mesh_table_free(newtbl);
-endgrow:
-       return NULL;
 }
 
 /**
  * ieee80211_new_mesh_header - create a new mesh header
  * @meshhdr:    uninitialized mesh header
  * @sdata:     mesh interface to be used
+ * @addr4:     addr4 of the mesh frame (1st in ae header)
+ *              may be NULL
+ * @addr5:     addr5 of the mesh frame (1st or 2nd in ae header)
+ *              may be NULL unless addr6 is present
+ * @addr6:     addr6 of the mesh frame (2nd or 3rd in ae header)
+ *             may be NULL unless addr5 is present
  *
  * Return the header length.
  */
 int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
-               struct ieee80211_sub_if_data *sdata)
+               struct ieee80211_sub_if_data *sdata, char *addr4,
+               char *addr5, char *addr6)
 {
-       meshhdr->flags = 0;
+       int aelen = 0;
+       memset(meshhdr, 0, sizeof(meshhdr));
        meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
        put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
        sdata->u.mesh.mesh_seqnum++;
-
-       return 6;
+       if (addr4) {
+               meshhdr->flags |= MESH_FLAGS_AE_A4;
+               aelen += ETH_ALEN;
+               memcpy(meshhdr->eaddr1, addr4, ETH_ALEN);
+       }
+       if (addr5 && addr6) {
+               meshhdr->flags |= MESH_FLAGS_AE_A5_A6;
+               aelen += 2 * ETH_ALEN;
+               if (!addr4) {
+                       memcpy(meshhdr->eaddr1, addr5, ETH_ALEN);
+                       memcpy(meshhdr->eaddr2, addr6, ETH_ALEN);
+               } else {
+                       memcpy(meshhdr->eaddr2, addr5, ETH_ALEN);
+                       memcpy(meshhdr->eaddr3, addr6, ETH_ALEN);
+               }
+       }
+       return 6 + aelen;
 }
 
 static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
@@ -427,23 +434,50 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
 
        free_plinks = mesh_plink_availables(sdata);
        if (free_plinks != sdata->u.mesh.accepting_plinks)
-               ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
+               ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
 
-       ifmsh->housekeeping = false;
        mod_timer(&ifmsh->housekeeping_timer,
                  round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
 }
 
+#ifdef CONFIG_PM
+void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
+{
+       struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
+
+       /* might restart the timer but that doesn't matter */
+       cancel_work_sync(&ifmsh->work);
+
+       /* use atomic bitops in case both timers fire at the same time */
+
+       if (del_timer_sync(&ifmsh->housekeeping_timer))
+               set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
+       if (del_timer_sync(&ifmsh->mesh_path_timer))
+               set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
+}
+
+void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
+{
+       struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
+
+       if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
+               add_timer(&ifmsh->housekeeping_timer);
+       if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
+               add_timer(&ifmsh->mesh_path_timer);
+}
+#endif
 
 void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
 {
        struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
        struct ieee80211_local *local = sdata->local;
 
-       ifmsh->housekeeping = true;
-       queue_work(local->hw.workqueue, &ifmsh->work);
-       ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON |
-                                  IEEE80211_IFCC_BEACON_ENABLED);
+       set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
+       ieee80211_queue_work(&local->hw, &ifmsh->work);
+       sdata->vif.bss_conf.beacon_int = MESH_DEFAULT_BEACON_INTERVAL;
+       ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
+                                               BSS_CHANGED_BEACON_ENABLED |
+                                               BSS_CHANGED_BEACON_INT);
 }
 
 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
@@ -464,7 +498,7 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
         * should it be using the interface and enqueuing
         * frames at this very time on another CPU.
         */
-       synchronize_rcu();
+       rcu_barrier(); /* Wait for RX path and call_rcu()'s */
        skb_queue_purge(&sdata->u.mesh.skb_queue);
 }
 
@@ -519,7 +553,7 @@ static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
                                          struct ieee80211_rx_status *rx_status)
 {
        switch (mgmt->u.action.category) {
-       case PLINK_CATEGORY:
+       case MESH_PLINK_CATEGORY:
                mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
                break;
        case MESH_PATH_SEL_CATEGORY:
@@ -538,7 +572,7 @@ static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
 
        ifmsh = &sdata->u.mesh;
 
-       rx_status = (struct ieee80211_rx_status *) skb->cb;
+       rx_status = IEEE80211_SKB_RXCB(skb);
        mgmt = (struct ieee80211_mgmt *) skb->data;
        stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
 
@@ -567,7 +601,7 @@ static void ieee80211_mesh_work(struct work_struct *work)
        if (!netif_running(sdata->dev))
                return;
 
-       if (local->sw_scanning || local->hw_scanning)
+       if (local->scanning)
                return;
 
        while ((skb = skb_dequeue(&ifmsh->skb_queue)))
@@ -578,7 +612,13 @@ static void ieee80211_mesh_work(struct work_struct *work)
                       ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
                mesh_path_start_discovery(sdata);
 
-       if (ifmsh->housekeeping)
+       if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
+               mesh_mpath_table_grow();
+
+       if (test_and_clear_bit(MESH_WORK_GROW_MPATH_TABLE, &ifmsh->wrkq_flags))
+               mesh_mpp_table_grow();
+
+       if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
                ieee80211_mesh_housekeeping(sdata, ifmsh);
 }
 
@@ -589,7 +629,7 @@ void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
        rcu_read_lock();
        list_for_each_entry_rcu(sdata, &local->interfaces, list)
                if (ieee80211_vif_is_mesh(&sdata->vif))
-                       queue_work(local->hw.workqueue, &sdata->u.mesh.work);
+                       ieee80211_queue_work(&local->hw, &sdata->u.mesh.work);
        rcu_read_unlock();
 }
 
@@ -641,8 +681,7 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
 }
 
 ieee80211_rx_result
-ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
-                      struct ieee80211_rx_status *rx_status)
+ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
 {
        struct ieee80211_local *local = sdata->local;
        struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
@@ -656,12 +695,14 @@ ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
        fc = le16_to_cpu(mgmt->frame_control);
 
        switch (fc & IEEE80211_FCTL_STYPE) {
+       case IEEE80211_STYPE_ACTION:
+               if (skb->len < IEEE80211_MIN_ACTION_SIZE)
+                       return RX_DROP_MONITOR;
+               /* fall through */
        case IEEE80211_STYPE_PROBE_RESP:
        case IEEE80211_STYPE_BEACON:
-       case IEEE80211_STYPE_ACTION:
-               memcpy(skb->cb, rx_status, sizeof(*rx_status));
                skb_queue_tail(&ifmsh->skb_queue, skb);
-               queue_work(local->hw.workqueue, &ifmsh->work);
+               ieee80211_queue_work(&local->hw, &ifmsh->work);
                return RX_QUEUED;
        }