]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - src/ap/ieee802_11_shared.c
WNM: Additional BSS Transition Management capability
[thirdparty/hostap.git] / src / ap / ieee802_11_shared.c
index d325da59114d37f2dfde1ce18ffeb42286c1938a..76f78a7dbd9c1fde8f1eac7bfa2acadb42aef97d 100644 (file)
@@ -1,15 +1,9 @@
 /*
  * hostapd / IEEE 802.11 Management
- * Copyright (c) 2002-2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #include "utils/includes.h"
@@ -20,6 +14,7 @@
 #include "sta_info.h"
 #include "ap_config.h"
 #include "ap_drv_ops.h"
+#include "ieee802_11.h"
 
 
 #ifdef CONFIG_IEEE80211W
@@ -73,13 +68,13 @@ void ieee802_11_send_sa_query_req(struct hostapd_data *hapd,
        os_memcpy(mgmt.u.action.u.sa_query_req.trans_id, trans_id,
                  WLAN_SA_QUERY_TR_ID_LEN);
        end = mgmt.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
-       if (hostapd_drv_send_mlme(hapd, &mgmt, end - (u8 *) &mgmt) < 0)
+       if (hostapd_drv_send_mlme(hapd, &mgmt, end - (u8 *) &mgmt, 0) < 0)
                perror("ieee802_11_send_sa_query_req: send");
 }
 
 
-void ieee802_11_send_sa_query_resp(struct hostapd_data *hapd,
-                                  const u8 *sa, const u8 *trans_id)
+static void ieee802_11_send_sa_query_resp(struct hostapd_data *hapd,
+                                         const u8 *sa, const u8 *trans_id)
 {
        struct sta_info *sta;
        struct ieee80211_mgmt resp;
@@ -111,7 +106,7 @@ void ieee802_11_send_sa_query_resp(struct hostapd_data *hapd,
        os_memcpy(resp.u.action.u.sa_query_req.trans_id, trans_id,
                  WLAN_SA_QUERY_TR_ID_LEN);
        end = resp.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN;
-       if (hostapd_drv_send_mlme(hapd, &resp, end - (u8 *) &resp) < 0)
+       if (hostapd_drv_send_mlme(hapd, &resp, end - (u8 *) &resp, 0) < 0)
                perror("ieee80211_mgmt_sa_query_request: send");
 }
 
@@ -178,6 +173,14 @@ u8 * hostapd_eid_ext_capab(struct hostapd_data *hapd, u8 *eid)
                len = 5;
        if (len < 4 && hapd->conf->interworking)
                len = 4;
+       if (len < 3 && hapd->conf->wnm_sleep_mode)
+               len = 3;
+       if (len < 7 && hapd->conf->ssid.utf8_ssid)
+               len = 7;
+#ifdef CONFIG_WNM
+       if (len < 4)
+               len = 4;
+#endif /* CONFIG_WNM */
        if (len == 0)
                return eid;
 
@@ -185,9 +188,22 @@ u8 * hostapd_eid_ext_capab(struct hostapd_data *hapd, u8 *eid)
        *pos++ = len;
        *pos++ = 0x00;
        *pos++ = 0x00;
-       *pos++ = 0x00;
 
        *pos = 0x00;
+       if (hapd->conf->wnm_sleep_mode)
+               *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */
+       if (hapd->conf->bss_transition)
+               *pos |= 0x08; /* Bit 19 - BSS Transition */
+       pos++;
+
+       if (len < 4)
+               return pos;
+       *pos = 0x00;
+#ifdef CONFIG_WNM
+       *pos |= 0x02; /* Bit 25 - SSID List */
+#endif /* CONFIG_WNM */
+       if (hapd->conf->time_advertisement == 2)
+               *pos |= 0x08; /* Bit 27 - UTC TSF Offset */
        if (hapd->conf->interworking)
                *pos |= 0x80; /* Bit 31 - Interworking */
        pos++;
@@ -201,6 +217,18 @@ u8 * hostapd_eid_ext_capab(struct hostapd_data *hapd, u8 *eid)
                *pos |= 0x80; /* Bit 39 - TDLS Channel Switching Prohibited */
        pos++;
 
+       if (len < 6)
+               return pos;
+       *pos = 0x00;
+       pos++;
+
+       if (len < 7)
+               return pos;
+       *pos = 0x00;
+       if (hapd->conf->ssid.utf8_ssid)
+               *pos |= 0x01; /* Bit 48 - UTF-8 SSID */
+       pos++;
+
        return pos;
 }
 
@@ -243,3 +271,188 @@ u8 * hostapd_eid_interworking(struct hostapd_data *hapd, u8 *eid)
 
        return pos;
 }
+
+
+u8 * hostapd_eid_adv_proto(struct hostapd_data *hapd, u8 *eid)
+{
+       u8 *pos = eid;
+#ifdef CONFIG_INTERWORKING
+
+       /* TODO: Separate configuration for ANQP? */
+       if (!hapd->conf->interworking)
+               return eid;
+
+       *pos++ = WLAN_EID_ADV_PROTO;
+       *pos++ = 2;
+       *pos++ = 0x7F; /* Query Response Length Limit | PAME-BI */
+       *pos++ = ACCESS_NETWORK_QUERY_PROTOCOL;
+#endif /* CONFIG_INTERWORKING */
+
+       return pos;
+}
+
+
+u8 * hostapd_eid_roaming_consortium(struct hostapd_data *hapd, u8 *eid)
+{
+       u8 *pos = eid;
+#ifdef CONFIG_INTERWORKING
+       u8 *len;
+       unsigned int i, count;
+
+       if (!hapd->conf->interworking ||
+           hapd->conf->roaming_consortium == NULL ||
+           hapd->conf->roaming_consortium_count == 0)
+               return eid;
+
+       *pos++ = WLAN_EID_ROAMING_CONSORTIUM;
+       len = pos++;
+
+       /* Number of ANQP OIs (in addition to the max 3 listed here) */
+       if (hapd->conf->roaming_consortium_count > 3 + 255)
+               *pos++ = 255;
+       else if (hapd->conf->roaming_consortium_count > 3)
+               *pos++ = hapd->conf->roaming_consortium_count - 3;
+       else
+               *pos++ = 0;
+
+       /* OU #1 and #2 Lengths */
+       *pos = hapd->conf->roaming_consortium[0].len;
+       if (hapd->conf->roaming_consortium_count > 1)
+               *pos |= hapd->conf->roaming_consortium[1].len << 4;
+       pos++;
+
+       if (hapd->conf->roaming_consortium_count > 3)
+               count = 3;
+       else
+               count = hapd->conf->roaming_consortium_count;
+
+       for (i = 0; i < count; i++) {
+               os_memcpy(pos, hapd->conf->roaming_consortium[i].oi,
+                         hapd->conf->roaming_consortium[i].len);
+               pos += hapd->conf->roaming_consortium[i].len;
+       }
+
+       *len = pos - len - 1;
+#endif /* CONFIG_INTERWORKING */
+
+       return pos;
+}
+
+
+u8 * hostapd_eid_time_adv(struct hostapd_data *hapd, u8 *eid)
+{
+       if (hapd->conf->time_advertisement != 2)
+               return eid;
+
+       if (hapd->time_adv == NULL &&
+           hostapd_update_time_adv(hapd) < 0)
+               return eid;
+
+       if (hapd->time_adv == NULL)
+               return eid;
+
+       os_memcpy(eid, wpabuf_head(hapd->time_adv),
+                 wpabuf_len(hapd->time_adv));
+       eid += wpabuf_len(hapd->time_adv);
+
+       return eid;
+}
+
+
+u8 * hostapd_eid_time_zone(struct hostapd_data *hapd, u8 *eid)
+{
+       size_t len;
+
+       if (hapd->conf->time_advertisement != 2)
+               return eid;
+
+       len = os_strlen(hapd->conf->time_zone);
+
+       *eid++ = WLAN_EID_TIME_ZONE;
+       *eid++ = len;
+       os_memcpy(eid, hapd->conf->time_zone, len);
+       eid += len;
+
+       return eid;
+}
+
+
+int hostapd_update_time_adv(struct hostapd_data *hapd)
+{
+       const int elen = 2 + 1 + 10 + 5 + 1;
+       struct os_time t;
+       struct os_tm tm;
+       u8 *pos;
+
+       if (hapd->conf->time_advertisement != 2)
+               return 0;
+
+       if (os_get_time(&t) < 0 || os_gmtime(t.sec, &tm) < 0)
+               return -1;
+
+       if (!hapd->time_adv) {
+               hapd->time_adv = wpabuf_alloc(elen);
+               if (hapd->time_adv == NULL)
+                       return -1;
+               pos = wpabuf_put(hapd->time_adv, elen);
+       } else
+               pos = wpabuf_mhead_u8(hapd->time_adv);
+
+       *pos++ = WLAN_EID_TIME_ADVERTISEMENT;
+       *pos++ = 1 + 10 + 5 + 1;
+
+       *pos++ = 2; /* UTC time at which the TSF timer is 0 */
+
+       /* Time Value at TSF 0 */
+       /* FIX: need to calculate this based on the current TSF value */
+       WPA_PUT_LE16(pos, tm.year); /* Year */
+       pos += 2;
+       *pos++ = tm.month; /* Month */
+       *pos++ = tm.day; /* Day of month */
+       *pos++ = tm.hour; /* Hours */
+       *pos++ = tm.min; /* Minutes */
+       *pos++ = tm.sec; /* Seconds */
+       WPA_PUT_LE16(pos, 0); /* Milliseconds (not used) */
+       pos += 2;
+       *pos++ = 0; /* Reserved */
+
+       /* Time Error */
+       /* TODO: fill in an estimate on the error */
+       *pos++ = 0;
+       *pos++ = 0;
+       *pos++ = 0;
+       *pos++ = 0;
+       *pos++ = 0;
+
+       *pos++ = hapd->time_update_counter++;
+
+       return 0;
+}
+
+
+u8 * hostapd_eid_bss_max_idle_period(struct hostapd_data *hapd, u8 *eid)
+{
+       u8 *pos = eid;
+
+#ifdef CONFIG_WNM
+       if (hapd->conf->ap_max_inactivity > 0) {
+               unsigned int val;
+               *pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD;
+               *pos++ = 3;
+               val = hapd->conf->ap_max_inactivity;
+               if (val > 68000)
+                       val = 68000;
+               val *= 1000;
+               val /= 1024;
+               if (val == 0)
+                       val = 1;
+               if (val > 65535)
+                       val = 65535;
+               WPA_PUT_LE16(pos, val);
+               pos += 2;
+               *pos++ = 0x00; /* TODO: Protected Keep-Alive Required */
+       }
+#endif /* CONFIG_WNM */
+
+       return pos;
+}