mac80211: use fixed broadcast address
[pandora-kernel.git] / net / mac80211 / mesh.c
index a49a337..3a0683b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008 open80211s Ltd.
+ * Copyright (c) 2008, 2009 open80211s Ltd.
  * Authors:    Luis Carlos Cobo <luisca@cozybit.com>
  *            Javier Cardona <javier@cozybit.com>
  *
@@ -14,6 +14,7 @@
 
 #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
 #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
+#define IEEE80211_MESH_RANN_INTERVAL        (1 * HZ)
 
 #define MESHCONF_PP_OFFSET     0               /* Path Selection Protocol */
 #define MESHCONF_PM_OFFSET     1               /* Path Selection Metric   */
@@ -26,6 +27,7 @@
 
 #define TMR_RUNNING_HK 0
 #define TMR_RUNNING_MP 1
+#define TMR_RUNNING_MPR        2
 
 int mesh_allocated;
 static struct kmem_cache *rm_cache;
@@ -223,6 +225,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;
@@ -246,6 +249,13 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
                }
        }
 
+       if (sband->band == IEEE80211_BAND_2GHZ) {
+               pos = skb_put(skb, 2 + 1);
+               *pos++ = WLAN_EID_DS_PARAMS;
+               *pos++ = 1;
+               *pos++ = ieee80211_frequency_to_channel(local->hw.conf.channel->center_freq);
+       }
+
        pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len);
        *pos++ = WLAN_EID_MESH_ID;
        *pos++ = sdata->u.mesh.mesh_id_len;
@@ -271,9 +281,11 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
        /* Authentication Protocol identifier */
        *pos++ = sdata->u.mesh.mesh_auth_id;
 
-       /* Mesh Formation Info */
-       memset(pos, 0x00, 1);
-       pos += 1;
+       /* 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);
@@ -344,6 +356,34 @@ static void ieee80211_mesh_path_timer(unsigned long data)
        ieee80211_queue_work(&local->hw, &ifmsh->work);
 }
 
+static void ieee80211_mesh_path_root_timer(unsigned long data)
+{
+       struct ieee80211_sub_if_data *sdata =
+               (struct ieee80211_sub_if_data *) data;
+       struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
+       struct ieee80211_local *local = sdata->local;
+
+       set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
+
+       if (local->quiescing) {
+               set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
+               return;
+       }
+
+       ieee80211_queue_work(&local->hw, &ifmsh->work);
+}
+
+void ieee80211_mesh_root_setup(struct ieee80211_if_mesh *ifmsh)
+{
+       if (ifmsh->mshcfg.dot11MeshHWMPRootMode)
+               set_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
+       else {
+               clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags);
+               /* stop running timer */
+               del_timer_sync(&ifmsh->mesh_path_root_timer);
+       }
+}
+
 /**
  * ieee80211_fill_mesh_addresses - fill addresses of a locally originated mesh frame
  * @hdr:       802.11 frame header
@@ -354,8 +394,9 @@ static void ieee80211_mesh_path_timer(unsigned long data)
  *
  * 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) {
+int ieee80211_fill_mesh_addresses(struct ieee80211_hdr *hdr, __le16 *fc,
+                                 const u8 *meshda, const u8 *meshsa)
+{
        if (is_multicast_ether_addr(meshda)) {
                *fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
                /* DA TA SA */
@@ -437,6 +478,15 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
                  round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
 }
 
+static void ieee80211_mesh_rootpath(struct ieee80211_sub_if_data *sdata)
+{
+       struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
+
+       mesh_path_tx_root_frame(sdata);
+       mod_timer(&ifmsh->mesh_path_root_timer,
+                 round_jiffies(jiffies + IEEE80211_MESH_RANN_INTERVAL));
+}
+
 #ifdef CONFIG_PM
 void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
 {
@@ -451,6 +501,8 @@ void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
                set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
        if (del_timer_sync(&ifmsh->mesh_path_timer))
                set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
+       if (del_timer_sync(&ifmsh->mesh_path_root_timer))
+               set_bit(TMR_RUNNING_MPR, &ifmsh->timers_running);
 }
 
 void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
@@ -461,6 +513,9 @@ void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
                add_timer(&ifmsh->housekeeping_timer);
        if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
                add_timer(&ifmsh->mesh_path_timer);
+       if (test_and_clear_bit(TMR_RUNNING_MPR, &ifmsh->timers_running))
+               add_timer(&ifmsh->mesh_path_root_timer);
+       ieee80211_mesh_root_setup(ifmsh);
 }
 #endif
 
@@ -470,6 +525,7 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
        struct ieee80211_local *local = sdata->local;
 
        set_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags);
+       ieee80211_mesh_root_setup(ifmsh);
        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 |
@@ -480,6 +536,7 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
 void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
 {
        del_timer_sync(&sdata->u.mesh.housekeeping_timer);
+       del_timer_sync(&sdata->u.mesh.mesh_path_root_timer);
        /*
         * If the timer fired while we waited for it, it will have
         * requeued the work. Now the work will be running again
@@ -550,7 +607,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:
@@ -617,6 +674,9 @@ static void ieee80211_mesh_work(struct work_struct *work)
 
        if (test_and_clear_bit(MESH_WORK_HOUSEKEEPING, &ifmsh->wrkq_flags))
                ieee80211_mesh_housekeeping(sdata, ifmsh);
+
+       if (test_and_clear_bit(MESH_WORK_ROOT, &ifmsh->wrkq_flags))
+               ieee80211_mesh_rootpath(sdata);
 }
 
 void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
@@ -662,7 +722,7 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
                MESH_MIN_DISCOVERY_TIMEOUT;
        ifmsh->accepting_plinks = true;
        ifmsh->preq_id = 0;
-       ifmsh->dsn = 0;
+       ifmsh->sn = 0;
        atomic_set(&ifmsh->mpaths, 0);
        mesh_rmc_init(sdata);
        ifmsh->last_preq = jiffies;
@@ -673,6 +733,9 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
        setup_timer(&ifmsh->mesh_path_timer,
                    ieee80211_mesh_path_timer,
                    (unsigned long) sdata);
+       setup_timer(&ifmsh->mesh_path_root_timer,
+                   ieee80211_mesh_path_root_timer,
+                   (unsigned long) sdata);
        INIT_LIST_HEAD(&ifmsh->preq_queue.list);
        spin_lock_init(&ifmsh->mesh_preq_queue_lock);
 }