]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
FT: Add set/get session_timeout callback functions
authorMichael Braun <michael-dev@fami-braun.de>
Thu, 18 May 2017 13:21:56 +0000 (15:21 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 6 Apr 2018 16:48:15 +0000 (19:48 +0300)
These are needed to allow wpa_auth_ft.c to control session_timeout
values for STAs.

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

index 638a80bea209766354d3d9558fde9ad4fe030f58..3a8712a0d27cc17897629f80fd4e1e3862ca3540 100644 (file)
@@ -275,6 +275,9 @@ struct wpa_auth_callbacks {
        int (*set_radius_cui)(void *ctx, const u8 *sta_addr,
                              const u8 *radius_cui, size_t radius_cui_len);
        size_t (*get_radius_cui)(void *ctx, const u8 *sta_addr, const u8 **buf);
+       void (*set_session_timeout)(void *ctx, const u8 *sta_addr,
+                                   int session_timeout);
+       int (*get_session_timeout)(void *ctx, const u8 *sta_addr);
 
        int (*send_ft_action)(void *ctx, const u8 *dst,
                              const u8 *data, size_t data_len);
index 229daef607e6c19a82145b99dc09fae4d84f6aae..812740301c8b210f0ccf9ea0dade8b06ea51d618 100644 (file)
@@ -1030,6 +1030,50 @@ hostapd_wpa_auth_get_radius_cui(void *ctx, const u8 *sta_addr, const u8 **buf)
 }
 
 
+static void hostapd_wpa_auth_set_session_timeout(void *ctx, const u8 *sta_addr,
+                                                int session_timeout)
+{
+       struct hostapd_data *hapd = ctx;
+       struct sta_info *sta;
+
+       sta = ap_get_sta(hapd, sta_addr);
+       if (!sta)
+               return;
+
+       if (session_timeout) {
+               os_get_reltime(&sta->session_timeout);
+               sta->session_timeout.sec += session_timeout;
+               sta->session_timeout_set = 1;
+               ap_sta_session_timeout(hapd, sta, session_timeout);
+       } else {
+               sta->session_timeout_set = 0;
+               ap_sta_no_session_timeout(hapd, sta);
+       }
+}
+
+
+static int hostapd_wpa_auth_get_session_timeout(void *ctx, const u8 *sta_addr)
+{
+       struct hostapd_data *hapd = ctx;
+       struct sta_info *sta;
+       struct os_reltime now, remaining;
+
+       sta = ap_get_sta(hapd, sta_addr);
+       if (!sta || !sta->session_timeout_set)
+               return 0;
+
+       os_get_reltime(&now);
+       if (os_reltime_before(&sta->session_timeout, &now)) {
+               /* already expired, return >0 as timeout was set */
+               return 1;
+       }
+
+       os_reltime_sub(&sta->session_timeout, &now, &remaining);
+
+       return (remaining.sec > 0) ? remaining.sec : 1;
+}
+
+
 static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
                                size_t len)
 {
@@ -1155,6 +1199,8 @@ int hostapd_setup_wpa(struct hostapd_data *hapd)
                .get_identity = hostapd_wpa_auth_get_identity,
                .set_radius_cui = hostapd_wpa_auth_set_radius_cui,
                .get_radius_cui = hostapd_wpa_auth_get_radius_cui,
+               .set_session_timeout = hostapd_wpa_auth_set_session_timeout,
+               .get_session_timeout = hostapd_wpa_auth_get_session_timeout,
 #endif /* CONFIG_IEEE80211R_AP */
        };
        const u8 *wpa_ie;