VHT: Store VHT capabilities and manage VHT flag for STAs
[mech_eap.git] / src / ap / ieee802_11_vht.c
1 /*
2  * hostapd / IEEE 802.11ac VHT
3  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of BSD license
7  *
8  * See README and COPYING for more details.
9  */
10
11 #include "utils/includes.h"
12
13 #include "utils/common.h"
14 #include "common/ieee802_11_defs.h"
15 #include "drivers/driver.h"
16 #include "hostapd.h"
17 #include "ap_config.h"
18 #include "sta_info.h"
19 #include "beacon.h"
20 #include "ieee802_11.h"
21
22
23 u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid)
24 {
25         struct ieee80211_vht_capabilities *cap;
26         u8 *pos = eid;
27
28         if (!hapd->iconf->ieee80211ac || !hapd->iface->current_mode ||
29             hapd->conf->disable_11ac)
30                 return eid;
31
32         *pos++ = WLAN_EID_VHT_CAP;
33         *pos++ = sizeof(*cap);
34
35         cap = (struct ieee80211_vht_capabilities *) pos;
36         os_memset(cap, 0, sizeof(*cap));
37         cap->vht_capabilities_info = host_to_le32(
38                 hapd->iface->current_mode->vht_capab);
39
40         /* Supported MCS set comes from hw */
41         os_memcpy(cap->vht_supported_mcs_set,
42                   hapd->iface->current_mode->vht_mcs_set, 8);
43
44         pos += sizeof(*cap);
45
46         return pos;
47 }
48
49
50 u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
51 {
52         struct ieee80211_vht_operation *oper;
53         u8 *pos = eid;
54
55         if (!hapd->iconf->ieee80211ac || hapd->conf->disable_11ac)
56                 return eid;
57
58         *pos++ = WLAN_EID_VHT_OPERATION;
59         *pos++ = sizeof(*oper);
60
61         oper = (struct ieee80211_vht_operation *) pos;
62         os_memset(oper, 0, sizeof(*oper));
63
64         oper->vht_op_info_chwidth = hapd->iconf->vht_oper_chwidth;
65
66         /* VHT Basic MCS set comes from hw */
67         /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
68         oper->vht_basic_mcs_set = host_to_le16(0xfffc);
69         pos += sizeof(*oper);
70
71         return pos;
72 }
73
74
75 u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
76                        const u8 *vht_capab, size_t vht_capab_len)
77 {
78         /* Disable VHT caps for STAs associated to no-VHT BSSes. */
79         if (!vht_capab ||
80             vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
81             hapd->conf->disable_11ac) {
82                 sta->flags &= ~WLAN_STA_VHT;
83                 os_free(sta->vht_capabilities);
84                 sta->vht_capabilities = NULL;
85                 return WLAN_STATUS_SUCCESS;
86         }
87
88         if (sta->vht_capabilities == NULL) {
89                 sta->vht_capabilities =
90                         os_zalloc(sizeof(struct ieee80211_vht_capabilities));
91                 if (sta->vht_capabilities == NULL)
92                         return WLAN_STATUS_UNSPECIFIED_FAILURE;
93         }
94
95         sta->flags |= WLAN_STA_VHT;
96         os_memcpy(sta->vht_capabilities, vht_capab,
97                   sizeof(struct ieee80211_vht_capabilities));
98
99         return WLAN_STATUS_SUCCESS;
100 }