cozybit / wpa_supplicant-o11s-legacy

wpa_supplicant
Other
6 stars 10 forks source link

Add support of sending PLINK_CLOSE frame before leaving mesh #5

Closed chunyeow closed 11 years ago

chunyeow commented 11 years ago
From f1fb92e4503cb7f91cccac06e32915a2818c6f88 Mon Sep 17 00:00:00 2001
From: Chun-Yeow Yeoh <yeohchunyeow@cozybit.com>
Date: Fri, 9 Aug 2013 17:14:37 -0700
Subject: [PATCH] mesh: send plink close to all mesh STAs while leaving mesh

Sending plink close frame to all mesh STAs while leaving mesh.
We need to do this after only we have joined the mesh network. So,
introduce a flag to indicate that we have successfully joining
the mesh network before doing so.

Signed-off-by: Chun-Yeow Yeoh <yeohchunyeow@cozybit.com>

---
 wpa_supplicant/mesh.c             |   12 ++++++++++++
 wpa_supplicant/mesh.h             |    2 ++
 wpa_supplicant/mesh_mpm.c         |   13 +++++++++++++
 wpa_supplicant/wpa_supplicant_i.h |    1 +
 4 files changed, 28 insertions(+)

diff --git a/wpa_supplicant/mesh.c b/wpa_supplicant/mesh.c
index 8f7865e..d72207f 100644
--- a/wpa_supplicant/mesh.c
+++ b/wpa_supplicant/mesh.c
@@ -177,6 +177,8 @@ wpa_supplicant_mesh_init(struct wpa_supplicant *wpa_s,
            goto out_free;
    }

+   wpa_s->join_mesh = 0;
+
    return 0;
 out_free:
    wpa_supplicant_mesh_deinit(wpa_s);
@@ -251,6 +253,9 @@ int wpa_supplicant_join_mesh(struct wpa_supplicant *wpa_s,
    ret = wpa_drv_join_mesh(wpa_s, &params);
    if (ret)
        wpa_msg(wpa_s, MSG_ERROR, "mesh join error=%d", ret);
+   else
+       /* Set this after joining the mesh */
+       wpa_s->join_mesh = 1;

    /* hostapd sets the interface down until we associate */
    wpa_drv_set_operstate(wpa_s, 1);
@@ -262,6 +267,13 @@ out:
 void wpa_supplicant_leave_mesh(struct wpa_supplicant *wpa_s)
 {
    int ret = 0;
+   struct hostapd_data *bss;
+
+   /* Send all the peering close frame to all mesh STAs before leaving */
+   if (wpa_s->join_mesh) {
+       bss = wpa_s->ifmsh->bss[0];
+       ap_for_each_sta(bss, mesh_deactivate_sta, wpa_s);
+   }

    wpa_msg(wpa_s, MSG_INFO, "leaving mesh");
    ret = wpa_drv_leave_mesh(wpa_s);
diff --git a/wpa_supplicant/mesh.h b/wpa_supplicant/mesh.h
index 1b2895b..b12367e 100644
--- a/wpa_supplicant/mesh.h
+++ b/wpa_supplicant/mesh.h
@@ -32,4 +32,6 @@ void wpa_supplicant_leave_mesh(struct wpa_supplicant *wpa_s);
 void wpa_mesh_notify_peer(struct wpa_supplicant *wpa_s, const u8 *addr,
              const u8 *ies, int ie_len);
 void wpa_supplicant_mesh_iface_deinit(struct hostapd_iface *ifmsh);
+int mesh_deactivate_sta(struct hostapd_data *hapd,
+           struct sta_info *sta, void *ctx);
 #endif /* MESH_H */
diff --git a/wpa_supplicant/mesh_mpm.c b/wpa_supplicant/mesh_mpm.c
index 5df0a57..04a9377 100644
--- a/wpa_supplicant/mesh_mpm.c
+++ b/wpa_supplicant/mesh_mpm.c
@@ -801,3 +801,16 @@ void mesh_mpm_action_rx(struct wpa_supplicant *wpa_s,
    }
    mesh_mpm_fsm(wpa_s, sta, event);
 }
+
+int mesh_deactivate_sta(struct hostapd_data *hapd,
+           struct sta_info *sta, void *ctx)
+{
+   if (sta->plink_state == PLINK_ESTAB) {
+       mesh_mpm_send_plink_action(ctx, sta, PLINK_CLOSE, 0);
+       wpa_printf(MSG_DEBUG, "Mesh MPM: send plink close to " MACSTR,
+              MAC2STR(sta->addr));
+       return 1;
+   }
+
+   return 0;
+}
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 403c33e..10e8e99 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -532,6 +532,7 @@ struct wpa_supplicant {
 #ifdef CONFIG_MESH
    struct hostapd_iface *ifmsh;
    struct mesh_rsn *mesh_rsn;
+   char join_mesh; /* use to indicate whether we have join the mesh */
 #endif /* CONFIG_MESH */

    unsigned int off_channel_freq;
-- 
1.7.9.5
twpedersen commented 11 years ago

On Fri, Aug 9, 2013 at 5:29 PM, Chun-Yeow notifications@github.com wrote:

From f1fb92e4503cb7f91cccac06e32915a2818c6f88 Mon Sep 17 00:00:00 2001 From: Chun-Yeow Yeoh yeohchunyeow@cozybit.com Date: Fri, 9 Aug 2013 17:14:37 -0700 Subject: [PATCH] mesh: send plink close to all mesh STAs while leaving mesh

Sending plink close frame to all mesh STAs while leaving mesh. We need to do this after only we have joined the mesh network. So, introduce a flag to indicate that we have successfully joining the mesh network before doing so.

Signed-off-by: Chun-Yeow Yeoh yeohchunyeow@cozybit.com

wpa_supplicant/mesh.c | 12 ++++++++++++ wpa_supplicant/mesh.h | 2 ++ wpa_supplicant/mesh_mpm.c | 13 +++++++++++++ wpa_supplicant/wpa_supplicant_i.h | 1 + 4 files changed, 28 insertions(+)

diff --git a/wpa_supplicant/mesh.c b/wpa_supplicant/mesh.c index 8f7865e..d72207f 100644 --- a/wpa_supplicant/mesh.c +++ b/wpa_supplicant/mesh.c @@ -177,6 +177,8 @@ wpa_supplicant_mesh_init(struct wpa_supplicant *wpa_s, goto out_free; }

  • wpa_s->join_mesh = 0;

I think the tense is off here, maybe mesh_joined or mesh_up?

return 0;

out_free: wpa_supplicant_mesh_deinit(wpa_s); @@ -251,6 +253,9 @@ int wpa_supplicant_join_mesh(struct wpa_supplicant *wpa_s, ret = wpa_drv_join_mesh(wpa_s, &params); if (ret) wpa_msg(wpa_s, MSG_ERROR, "mesh join error=%d", ret);

  • else
  • /* Set this after joining the mesh */

This comment is redundant :)

  • wpa_s->join_mesh = 1;

    /* hostapd sets the interface down until we associate / wpa_drv_set_operstate(wpa_s, 1); @@ -262,6 +267,13 @@ out: void wpa_supplicant_leave_mesh(struct wpa_supplicant wpa_s) { int ret = 0;

  • struct hostapd_data *bss; +
  • /* Send all the peering close frame to all mesh STAs before leaving */
  • if (wpa_s->join_mesh) {
  • bss = wpa_s->ifmsh->bss[0];
  • ap_for_each_sta(bss, mesh_deactivate_sta, wpa_s);
  • }

    wpa_msg(wpa_s, MSG_INFO, "leaving mesh"); ret = wpa_drv_leave_mesh(wpa_s); diff --git a/wpa_supplicant/mesh.h b/wpa_supplicant/mesh.h index 1b2895b..b12367e 100644 --- a/wpa_supplicant/mesh.h +++ b/wpa_supplicant/mesh.h @@ -32,4 +32,6 @@ void wpa_supplicant_leave_mesh(struct wpa_supplicant wpa_s); void wpa_mesh_notify_peer(struct wpa_supplicant wpa_s, const u8 addr, const u8 ies, int ie_len); void wpa_supplicant_mesh_iface_deinit(struct hostapd_iface ifmsh); +int mesh_deactivate_sta(struct hostapd_data hapd,

  • struct sta_info _sta, void *ctx);

    endif /_ MESH_H */

    diff --git a/wpa_supplicant/mesh_mpm.c b/wpa_supplicant/mesh_mpm.c index 5df0a57..04a9377 100644 --- a/wpa_supplicant/mesh_mpm.c +++ b/wpa_supplicant/mesh_mpm.c @@ -801,3 +801,16 @@ void mesh_mpm_action_rx(struct wpa_supplicant wpa_s, } mesh_mpm_fsm(wpa_s, sta, event); } + +int mesh_deactivate_sta(struct hostapd_data hapd,

  • struct sta_info sta, void ctx)

Is this indentation right, or does github convert tabs to a certain amount of spaces?

+{

  • if (sta->plink_state == PLINK_ESTAB) {
  • mesh_mpm_send_plink_action(ctx, sta, PLINK_CLOSE, 0);

ctx is a void*, but that function takes a pointer to struct wpa_supplicant. This should result in a compile-time warning?

  • wpa_printf(MSG_DEBUG, "Mesh MPM: send plink close to " MACSTR,
  • MAC2STR(sta->addr));
  • return 1;

Are you sure only peers in ESTAB get a close frame?

  • } +
  • return 0; +} diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 403c33e..10e8e99 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -532,6 +532,7 @@ struct wpa_supplicant {

    ifdef CONFIG_MESH

    struct hostapd_iface ifmsh; struct mesh_rsn mesh_rsn;

  • char joinmesh; /* use to indicate whether we have join the mesh /

    endif /_ CONFIG_MESH */

    unsigned int off_channel_freq;

    1.7.9.5


You can merge this Pull Request by running

git pull https://github.com/cozybit/wpa_supplicant yeow-plink-close

Or view, comment on, or merge it at:

https://github.com/cozybit/wpa_supplicant/pull/5

Commit Summary

mesh: send plink close to all mesh STAs while leaving mesh

File Changes

M wpa_supplicant/mesh.c (12) M wpa_supplicant/mesh.h (2) M wpa_supplicant/mesh_mpm.c (13) M wpa_supplicant/wpa_supplicant_i.h (1)

Patch Links:

https://github.com/cozybit/wpa_supplicant/pull/5.patch https://github.com/cozybit/wpa_supplicant/pull/5.diff

Thomas

chunyeow commented 11 years ago
  • wpa_s->join_mesh = 0;

I think the tense is off here, maybe mesh_joined or mesh_up?

Ok, mesh_joined makes more sense here.

  • /* Set this after joining the mesh */

This comment is redundant :)

Ok, take this out

+int mesh_deactivate_sta(struct hostapd_data *hapd,

  • struct sta_info sta, void ctx)

Is this indentation right, or does github convert tabs to a certain amount of spaces?

Yes, indentation... three tabs. Github does convert?

+{

  • if (sta->plink_state == PLINK_ESTAB) {
  • mesh_mpm_send_plink_action(ctx, sta, PLINK_CLOSE, 0);

ctx is a void*, but that function takes a pointer to struct

wpa_supplicant. This should result in a compile-time warning?

No compile warning here. So should be correct.

  • wpa_printf(MSG_DEBUG, "Mesh MPM: send plink close to " MACSTR,
  • MAC2STR(sta->addr));
  • return 1;

Are you sure only peers in ESTAB get a close frame?

Ok, it seems that standard not specify anything on this. Maybe just simply send it as long as the peer mesh STA state it is not LISTEN.


Chun-Yeow

chunyeow commented 11 years ago

Just update the commit so that it can iterate to check all the mesh STAs and sending plink close frame if the plink state is available. (return 0 in mesh_deactivate_sta).

Let me know if you have other approach in mind.


Chun-Yeow