]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
FT: Add set_vlan()/get_vlan() callback functions
authorMichael Braun <michael-dev@fami-braun.de>
Thu, 18 May 2017 13:21:51 +0000 (15:21 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 5 Apr 2018 19:39:21 +0000 (22:39 +0300)
These are needed to allow wpa_auth_ft.c to control VLAN assignment for
STAs.

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
src/ap/wpa_auth.h
src/ap/wpa_auth_glue.c

index 189001fecef7bc6ad34f5664ac97e43c1962cfc1..666c65fe2079dfad08592fe7df9e58c8669b19b6 100644 (file)
@@ -14,6 +14,8 @@
 #include "common/wpa_common.h"
 #include "common/ieee802_11_defs.h"
 
+struct vlan_description;
+
 #define MAX_OWN_IE_OVERRIDE 256
 
 #ifdef _MSC_VER
@@ -257,6 +259,10 @@ struct wpa_auth_callbacks {
                        size_t data_len);
 #ifdef CONFIG_IEEE80211R_AP
        struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
+       int (*set_vlan)(void *ctx, const u8 *sta_addr,
+                       struct vlan_description *vlan);
+       int (*get_vlan)(void *ctx, const u8 *sta_addr,
+                       struct vlan_description *vlan);
        int (*send_ft_action)(void *ctx, const u8 *dst,
                              const u8 *data, size_t data_len);
        int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
index c891a352c12e9f04ea99989d21d13ce8733edc0a..16ab9921f89f70a70c8512f65033d9e5902d4680 100644 (file)
@@ -836,6 +836,58 @@ hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
 }
 
 
+static int hostapd_wpa_auth_set_vlan(void *ctx, const u8 *sta_addr,
+                                    struct vlan_description *vlan)
+{
+       struct hostapd_data *hapd = ctx;
+       struct sta_info *sta;
+
+       sta = ap_get_sta(hapd, sta_addr);
+       if (!sta || !sta->wpa_sm)
+               return -1;
+
+       if (vlan->notempty &&
+           !hostapd_vlan_valid(hapd->conf->vlan, vlan)) {
+               hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+                              HOSTAPD_LEVEL_INFO,
+                              "Invalid VLAN %d%s received from FT",
+                              vlan->untagged, vlan->tagged[0] ? "+" : "");
+               return -1;
+       }
+
+       if (ap_sta_set_vlan(hapd, sta, vlan) < 0)
+               return -1;
+       /* Configure wpa_group for GTK but ignore error due to driver not
+        * knowing this STA. */
+       ap_sta_bind_vlan(hapd, sta);
+
+       if (sta->vlan_id)
+               hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
+                              HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
+
+       return 0;
+}
+
+
+static int hostapd_wpa_auth_get_vlan(void *ctx, const u8 *sta_addr,
+                                    struct vlan_description *vlan)
+{
+       struct hostapd_data *hapd = ctx;
+       struct sta_info *sta;
+
+       sta = ap_get_sta(hapd, sta_addr);
+       if (!sta)
+               return -1;
+
+       if (sta->vlan_desc)
+               *vlan = *sta->vlan_desc;
+       else
+               os_memset(vlan, 0, sizeof(*vlan));
+
+       return 0;
+}
+
+
 static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
                                size_t len)
 {
@@ -955,6 +1007,8 @@ int hostapd_setup_wpa(struct hostapd_data *hapd)
                .send_ft_action = hostapd_wpa_auth_send_ft_action,
                .add_sta = hostapd_wpa_auth_add_sta,
                .add_tspec = hostapd_wpa_auth_add_tspec,
+               .set_vlan = hostapd_wpa_auth_set_vlan,
+               .get_vlan = hostapd_wpa_auth_get_vlan,
 #endif /* CONFIG_IEEE80211R_AP */
        };
        const u8 *wpa_ie;