drm/radeon/kms/pm: fix segfault in clock code
[linux-2.6.git] / net / mac80211 / mesh.c
index 222a313..6a43314 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>
  *
 
 #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   */
-#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
+#define TMR_RUNNING_MPR        2
 
 int mesh_allocated;
 static struct kmem_cache *rm_cache;
@@ -85,12 +81,11 @@ 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 &&
-               (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)))
+               (ifmsh->mesh_pp_id == ie->mesh_config->meshconf_psel) &&
+               (ifmsh->mesh_pm_id == ie->mesh_config->meshconf_pmetric) &&
+               (ifmsh->mesh_cc_id == ie->mesh_config->meshconf_congest) &&
+               (ifmsh->mesh_sp_id == ie->mesh_config->meshconf_synch) &&
+               (ifmsh->mesh_auth_id == ie->mesh_config->meshconf_auth))
                return true;
 
        return false;
@@ -103,7 +98,7 @@ 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 + MESHCONF_CAPAB_OFFSET) &
+       return (ie->mesh_config->meshconf_cap &
            MESHCONF_CAPAB_ACCEPT_PLINKS) != 0;
 }
 
@@ -200,8 +195,8 @@ int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
                        list_del(&p->list);
                        kmem_cache_free(rm_cache, p);
                        --entries;
-               } else if ((seqnum == p->seqnum)
-                               && (memcmp(sa, p->sa, ETH_ALEN) == 0))
+               } else if ((seqnum == p->seqnum) &&
+                          (memcmp(sa, p->sa, ETH_ALEN) == 0))
                        return -1;
        }
 
@@ -260,9 +255,9 @@ 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, 2 + IEEE80211_MESH_CONFIG_LEN);
+       pos = skb_put(skb, 2 + sizeof(struct ieee80211_meshconf_ie));
        *pos++ = WLAN_EID_MESH_CONFIG;
-       *pos++ = IEEE80211_MESH_CONFIG_LEN;
+       *pos++ = sizeof(struct ieee80211_meshconf_ie);
 
        /* Active path selection protocol ID */
        *pos++ = sdata->u.mesh.mesh_pp_id;
@@ -354,6 +349,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
@@ -364,8 +387,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 */
@@ -403,7 +427,7 @@ int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
                char *addr5, char *addr6)
 {
        int aelen = 0;
-       memset(meshhdr, 0, sizeof(meshhdr));
+       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++;
@@ -447,6 +471,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)
 {
@@ -461,6 +494,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)
@@ -471,6 +506,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
 
@@ -480,6 +518,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 |
@@ -490,6 +529,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
@@ -627,6 +667,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)
@@ -672,7 +715,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;
@@ -683,6 +726,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);
 }