xref: /freebsd/contrib/wpa/src/ap/wmm.c (revision a90b9d0159070121c221b966469c3e36d912bf82)
1e28a4053SRui Paulo /*
2e28a4053SRui Paulo  * hostapd / WMM (Wi-Fi Multimedia)
3e28a4053SRui Paulo  * Copyright 2002-2003, Instant802 Networks, Inc.
4e28a4053SRui Paulo  * Copyright 2005-2006, Devicescape Software, Inc.
5e28a4053SRui Paulo  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
6e28a4053SRui Paulo  *
75b9c547cSRui Paulo  * This software may be distributed under the terms of the BSD license.
85b9c547cSRui Paulo  * See README for more details.
9e28a4053SRui Paulo  */
10e28a4053SRui Paulo 
11e28a4053SRui Paulo #include "utils/includes.h"
12e28a4053SRui Paulo 
13e28a4053SRui Paulo #include "utils/common.h"
14e28a4053SRui Paulo #include "common/ieee802_11_defs.h"
15e28a4053SRui Paulo #include "common/ieee802_11_common.h"
16e28a4053SRui Paulo #include "hostapd.h"
17e28a4053SRui Paulo #include "ieee802_11.h"
18e28a4053SRui Paulo #include "sta_info.h"
19e28a4053SRui Paulo #include "ap_config.h"
20f05cddf9SRui Paulo #include "ap_drv_ops.h"
21e28a4053SRui Paulo #include "wmm.h"
22e28a4053SRui Paulo 
23e28a4053SRui Paulo 
wmm_aci_aifsn(int aifsn,int acm,int aci)24e28a4053SRui Paulo static inline u8 wmm_aci_aifsn(int aifsn, int acm, int aci)
25e28a4053SRui Paulo {
26e28a4053SRui Paulo 	u8 ret;
27e28a4053SRui Paulo 	ret = (aifsn << WMM_AC_AIFNS_SHIFT) & WMM_AC_AIFSN_MASK;
28e28a4053SRui Paulo 	if (acm)
29e28a4053SRui Paulo 		ret |= WMM_AC_ACM;
30e28a4053SRui Paulo 	ret |= (aci << WMM_AC_ACI_SHIFT) & WMM_AC_ACI_MASK;
31e28a4053SRui Paulo 	return ret;
32e28a4053SRui Paulo }
33e28a4053SRui Paulo 
34e28a4053SRui Paulo 
wmm_ecw(int ecwmin,int ecwmax)35e28a4053SRui Paulo static inline u8 wmm_ecw(int ecwmin, int ecwmax)
36e28a4053SRui Paulo {
37e28a4053SRui Paulo 	return ((ecwmin << WMM_AC_ECWMIN_SHIFT) & WMM_AC_ECWMIN_MASK) |
38e28a4053SRui Paulo 		((ecwmax << WMM_AC_ECWMAX_SHIFT) & WMM_AC_ECWMAX_MASK);
39e28a4053SRui Paulo }
40e28a4053SRui Paulo 
41e28a4053SRui Paulo 
42206b73d0SCy Schubert static void
wmm_set_regulatory_limit(const struct hostapd_wmm_ac_params * wmm_conf,struct hostapd_wmm_ac_params * wmm,const struct hostapd_wmm_rule * wmm_reg)43206b73d0SCy Schubert wmm_set_regulatory_limit(const struct hostapd_wmm_ac_params *wmm_conf,
44206b73d0SCy Schubert 			 struct hostapd_wmm_ac_params *wmm,
45206b73d0SCy Schubert 			 const struct hostapd_wmm_rule *wmm_reg)
46206b73d0SCy Schubert {
47206b73d0SCy Schubert 	int ac;
48206b73d0SCy Schubert 
49206b73d0SCy Schubert 	for (ac = 0; ac < WMM_AC_NUM; ac++) {
50206b73d0SCy Schubert 		wmm[ac].cwmin = MAX(wmm_conf[ac].cwmin, wmm_reg[ac].min_cwmin);
51206b73d0SCy Schubert 		wmm[ac].cwmax = MAX(wmm_conf[ac].cwmax, wmm_reg[ac].min_cwmax);
52206b73d0SCy Schubert 		wmm[ac].aifs = MAX(wmm_conf[ac].aifs, wmm_reg[ac].min_aifs);
53206b73d0SCy Schubert 		wmm[ac].txop_limit =
54206b73d0SCy Schubert 			MIN(wmm_conf[ac].txop_limit, wmm_reg[ac].max_txop);
55206b73d0SCy Schubert 		wmm[ac].admission_control_mandatory =
56206b73d0SCy Schubert 			wmm_conf[ac].admission_control_mandatory;
57206b73d0SCy Schubert 	}
58206b73d0SCy Schubert }
59206b73d0SCy Schubert 
60206b73d0SCy Schubert 
61206b73d0SCy Schubert /*
62206b73d0SCy Schubert  * Calculate WMM regulatory limit if any.
63206b73d0SCy Schubert  */
wmm_calc_regulatory_limit(struct hostapd_data * hapd,struct hostapd_wmm_ac_params * acp)64206b73d0SCy Schubert static void wmm_calc_regulatory_limit(struct hostapd_data *hapd,
65206b73d0SCy Schubert 				      struct hostapd_wmm_ac_params *acp)
66206b73d0SCy Schubert {
67206b73d0SCy Schubert 	struct hostapd_hw_modes *mode = hapd->iface->current_mode;
68206b73d0SCy Schubert 	int c;
69206b73d0SCy Schubert 
70206b73d0SCy Schubert 	os_memcpy(acp, hapd->iconf->wmm_ac_params,
71206b73d0SCy Schubert 		  sizeof(hapd->iconf->wmm_ac_params));
72206b73d0SCy Schubert 
73206b73d0SCy Schubert 	for (c = 0; mode && c < mode->num_channels; c++) {
74206b73d0SCy Schubert 		struct hostapd_channel_data *chan = &mode->channels[c];
75206b73d0SCy Schubert 
76206b73d0SCy Schubert 		if (chan->freq != hapd->iface->freq)
77206b73d0SCy Schubert 			continue;
78206b73d0SCy Schubert 
79206b73d0SCy Schubert 		if (chan->wmm_rules_valid)
80206b73d0SCy Schubert 			wmm_set_regulatory_limit(hapd->iconf->wmm_ac_params,
81206b73d0SCy Schubert 						 acp, chan->wmm_rules);
82206b73d0SCy Schubert 		break;
83206b73d0SCy Schubert 	}
84206b73d0SCy Schubert 
85206b73d0SCy Schubert 	/*
86206b73d0SCy Schubert 	 * Check if we need to update set count. Since both were initialized to
87206b73d0SCy Schubert 	 * zero we can compare the whole array in one shot.
88206b73d0SCy Schubert 	 */
89206b73d0SCy Schubert 	if (os_memcmp(acp, hapd->iface->prev_wmm,
90206b73d0SCy Schubert 		      sizeof(hapd->iconf->wmm_ac_params)) != 0) {
91206b73d0SCy Schubert 		os_memcpy(hapd->iface->prev_wmm, acp,
92206b73d0SCy Schubert 			  sizeof(hapd->iconf->wmm_ac_params));
93206b73d0SCy Schubert 		hapd->parameter_set_count++;
94206b73d0SCy Schubert 	}
95206b73d0SCy Schubert }
96206b73d0SCy Schubert 
97206b73d0SCy Schubert 
98e28a4053SRui Paulo /*
99e28a4053SRui Paulo  * Add WMM Parameter Element to Beacon, Probe Response, and (Re)Association
100e28a4053SRui Paulo  * Response frames.
101e28a4053SRui Paulo  */
hostapd_eid_wmm(struct hostapd_data * hapd,u8 * eid)102e28a4053SRui Paulo u8 * hostapd_eid_wmm(struct hostapd_data *hapd, u8 *eid)
103e28a4053SRui Paulo {
104e28a4053SRui Paulo 	u8 *pos = eid;
105e28a4053SRui Paulo 	struct wmm_parameter_element *wmm =
106e28a4053SRui Paulo 		(struct wmm_parameter_element *) (pos + 2);
107*c1d255d3SCy Schubert 	struct hostapd_wmm_ac_params wmmp[WMM_AC_NUM];
108e28a4053SRui Paulo 	int e;
109e28a4053SRui Paulo 
110*c1d255d3SCy Schubert 	os_memset(wmmp, 0, sizeof(wmmp));
111*c1d255d3SCy Schubert 
112e28a4053SRui Paulo 	if (!hapd->conf->wmm_enabled)
113e28a4053SRui Paulo 		return eid;
114206b73d0SCy Schubert 	wmm_calc_regulatory_limit(hapd, wmmp);
115e28a4053SRui Paulo 	eid[0] = WLAN_EID_VENDOR_SPECIFIC;
116e28a4053SRui Paulo 	wmm->oui[0] = 0x00;
117e28a4053SRui Paulo 	wmm->oui[1] = 0x50;
118e28a4053SRui Paulo 	wmm->oui[2] = 0xf2;
119e28a4053SRui Paulo 	wmm->oui_type = WMM_OUI_TYPE;
120e28a4053SRui Paulo 	wmm->oui_subtype = WMM_OUI_SUBTYPE_PARAMETER_ELEMENT;
121e28a4053SRui Paulo 	wmm->version = WMM_VERSION;
122e28a4053SRui Paulo 	wmm->qos_info = hapd->parameter_set_count & 0xf;
123e28a4053SRui Paulo 
124f05cddf9SRui Paulo 	if (hapd->conf->wmm_uapsd &&
125f05cddf9SRui Paulo 	    (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
126e28a4053SRui Paulo 		wmm->qos_info |= 0x80;
127e28a4053SRui Paulo 
128f05cddf9SRui Paulo 	wmm->reserved = 0;
129f05cddf9SRui Paulo 
130e28a4053SRui Paulo 	/* fill in a parameter set record for each AC */
131e28a4053SRui Paulo 	for (e = 0; e < 4; e++) {
132e28a4053SRui Paulo 		struct wmm_ac_parameter *ac = &wmm->ac[e];
133206b73d0SCy Schubert 		struct hostapd_wmm_ac_params *acp = &wmmp[e];
134e28a4053SRui Paulo 
135e28a4053SRui Paulo 		ac->aci_aifsn = wmm_aci_aifsn(acp->aifs,
136e28a4053SRui Paulo 					      acp->admission_control_mandatory,
137e28a4053SRui Paulo 					      e);
138e28a4053SRui Paulo 		ac->cw = wmm_ecw(acp->cwmin, acp->cwmax);
139e28a4053SRui Paulo 		ac->txop_limit = host_to_le16(acp->txop_limit);
140e28a4053SRui Paulo 	}
141e28a4053SRui Paulo 
142e28a4053SRui Paulo 	pos = (u8 *) (wmm + 1);
143e28a4053SRui Paulo 	eid[1] = pos - eid - 2; /* element length */
144e28a4053SRui Paulo 
145e28a4053SRui Paulo 	return pos;
146e28a4053SRui Paulo }
147e28a4053SRui Paulo 
148e28a4053SRui Paulo 
149f05cddf9SRui Paulo /*
150f05cddf9SRui Paulo  * This function is called when a station sends an association request with
151f05cddf9SRui Paulo  * WMM info element. The function returns 1 on success or 0 on any error in WMM
152f05cddf9SRui Paulo  * element. eid does not include Element ID and Length octets.
153f05cddf9SRui Paulo  */
hostapd_eid_wmm_valid(struct hostapd_data * hapd,const u8 * eid,size_t len)154e28a4053SRui Paulo int hostapd_eid_wmm_valid(struct hostapd_data *hapd, const u8 *eid, size_t len)
155e28a4053SRui Paulo {
156e28a4053SRui Paulo 	struct wmm_information_element *wmm;
157e28a4053SRui Paulo 
158e28a4053SRui Paulo 	wpa_hexdump(MSG_MSGDUMP, "WMM IE", eid, len);
159e28a4053SRui Paulo 
160e28a4053SRui Paulo 	if (len < sizeof(struct wmm_information_element)) {
161e28a4053SRui Paulo 		wpa_printf(MSG_DEBUG, "Too short WMM IE (len=%lu)",
162e28a4053SRui Paulo 			   (unsigned long) len);
163f05cddf9SRui Paulo 		return 0;
164e28a4053SRui Paulo 	}
165e28a4053SRui Paulo 
166e28a4053SRui Paulo 	wmm = (struct wmm_information_element *) eid;
167e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "Validating WMM IE: OUI %02x:%02x:%02x  "
168e28a4053SRui Paulo 		   "OUI type %d  OUI sub-type %d  version %d  QoS info 0x%x",
169e28a4053SRui Paulo 		   wmm->oui[0], wmm->oui[1], wmm->oui[2], wmm->oui_type,
170e28a4053SRui Paulo 		   wmm->oui_subtype, wmm->version, wmm->qos_info);
171e28a4053SRui Paulo 	if (wmm->oui_subtype != WMM_OUI_SUBTYPE_INFORMATION_ELEMENT ||
172e28a4053SRui Paulo 	    wmm->version != WMM_VERSION) {
173e28a4053SRui Paulo 		wpa_printf(MSG_DEBUG, "Unsupported WMM IE Subtype/Version");
174f05cddf9SRui Paulo 		return 0;
175e28a4053SRui Paulo 	}
176e28a4053SRui Paulo 
177f05cddf9SRui Paulo 	return 1;
178e28a4053SRui Paulo }
179e28a4053SRui Paulo 
180e28a4053SRui Paulo 
wmm_send_action(struct hostapd_data * hapd,const u8 * addr,const struct wmm_tspec_element * tspec,u8 action_code,u8 dialogue_token,u8 status_code)181e28a4053SRui Paulo static void wmm_send_action(struct hostapd_data *hapd, const u8 *addr,
182e28a4053SRui Paulo 			    const struct wmm_tspec_element *tspec,
183e28a4053SRui Paulo 			    u8 action_code, u8 dialogue_token, u8 status_code)
184e28a4053SRui Paulo {
185e28a4053SRui Paulo 	u8 buf[256];
186e28a4053SRui Paulo 	struct ieee80211_mgmt *m = (struct ieee80211_mgmt *) buf;
187e28a4053SRui Paulo 	struct wmm_tspec_element *t = (struct wmm_tspec_element *)
188e28a4053SRui Paulo 		m->u.action.u.wmm_action.variable;
189e28a4053SRui Paulo 	int len;
190e28a4053SRui Paulo 
191e28a4053SRui Paulo 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
192e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
193e28a4053SRui Paulo 		       "action response - reason %d", status_code);
194e28a4053SRui Paulo 	os_memset(buf, 0, sizeof(buf));
195e28a4053SRui Paulo 	m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
196e28a4053SRui Paulo 					WLAN_FC_STYPE_ACTION);
197e28a4053SRui Paulo 	os_memcpy(m->da, addr, ETH_ALEN);
198e28a4053SRui Paulo 	os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
199e28a4053SRui Paulo 	os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
200e28a4053SRui Paulo 	m->u.action.category = WLAN_ACTION_WMM;
201e28a4053SRui Paulo 	m->u.action.u.wmm_action.action_code = action_code;
202e28a4053SRui Paulo 	m->u.action.u.wmm_action.dialog_token = dialogue_token;
203e28a4053SRui Paulo 	m->u.action.u.wmm_action.status_code = status_code;
204e28a4053SRui Paulo 	os_memcpy(t, tspec, sizeof(struct wmm_tspec_element));
205e28a4053SRui Paulo 	len = ((u8 *) (t + 1)) - buf;
206e28a4053SRui Paulo 
207*c1d255d3SCy Schubert 	if (hostapd_drv_send_mlme(hapd, m, len, 0, NULL, 0, 0) < 0)
2085b9c547cSRui Paulo 		wpa_printf(MSG_INFO, "wmm_send_action: send failed");
209e28a4053SRui Paulo }
210e28a4053SRui Paulo 
211e28a4053SRui Paulo 
wmm_process_tspec(struct wmm_tspec_element * tspec)212e28a4053SRui Paulo int wmm_process_tspec(struct wmm_tspec_element *tspec)
213e28a4053SRui Paulo {
21485732ac8SCy Schubert 	u64 medium_time;
21585732ac8SCy Schubert 	unsigned int pps, duration;
21685732ac8SCy Schubert 	unsigned int up, psb, dir, tid;
217e28a4053SRui Paulo 	u16 val, surplus;
218e28a4053SRui Paulo 
219e28a4053SRui Paulo 	up = (tspec->ts_info[1] >> 3) & 0x07;
220e28a4053SRui Paulo 	psb = (tspec->ts_info[1] >> 2) & 0x01;
221e28a4053SRui Paulo 	dir = (tspec->ts_info[0] >> 5) & 0x03;
222e28a4053SRui Paulo 	tid = (tspec->ts_info[0] >> 1) & 0x0f;
223e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "WMM: TS Info: UP=%d PSB=%d Direction=%d TID=%d",
224e28a4053SRui Paulo 		   up, psb, dir, tid);
225e28a4053SRui Paulo 	val = le_to_host16(tspec->nominal_msdu_size);
226e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "WMM: Nominal MSDU Size: %d%s",
227e28a4053SRui Paulo 		   val & 0x7fff, val & 0x8000 ? " (fixed)" : "");
228e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "WMM: Mean Data Rate: %u bps",
229e28a4053SRui Paulo 		   le_to_host32(tspec->mean_data_rate));
230e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "WMM: Minimum PHY Rate: %u bps",
231e28a4053SRui Paulo 		   le_to_host32(tspec->minimum_phy_rate));
232e28a4053SRui Paulo 	val = le_to_host16(tspec->surplus_bandwidth_allowance);
233e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "WMM: Surplus Bandwidth Allowance: %u.%04u",
234e28a4053SRui Paulo 		   val >> 13, 10000 * (val & 0x1fff) / 0x2000);
235e28a4053SRui Paulo 
236e28a4053SRui Paulo 	val = le_to_host16(tspec->nominal_msdu_size);
237e28a4053SRui Paulo 	if (val == 0) {
238e28a4053SRui Paulo 		wpa_printf(MSG_DEBUG, "WMM: Invalid Nominal MSDU Size (0)");
239e28a4053SRui Paulo 		return WMM_ADDTS_STATUS_INVALID_PARAMETERS;
240e28a4053SRui Paulo 	}
241e28a4053SRui Paulo 	/* pps = Ceiling((Mean Data Rate / 8) / Nominal MSDU Size) */
242e28a4053SRui Paulo 	pps = ((le_to_host32(tspec->mean_data_rate) / 8) + val - 1) / val;
243e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "WMM: Packets-per-second estimate for TSPEC: %d",
244e28a4053SRui Paulo 		   pps);
245e28a4053SRui Paulo 
246e28a4053SRui Paulo 	if (le_to_host32(tspec->minimum_phy_rate) < 1000000) {
247e28a4053SRui Paulo 		wpa_printf(MSG_DEBUG, "WMM: Too small Minimum PHY Rate");
248e28a4053SRui Paulo 		return WMM_ADDTS_STATUS_INVALID_PARAMETERS;
249e28a4053SRui Paulo 	}
250e28a4053SRui Paulo 
251e28a4053SRui Paulo 	duration = (le_to_host16(tspec->nominal_msdu_size) & 0x7fff) * 8 /
252e28a4053SRui Paulo 		(le_to_host32(tspec->minimum_phy_rate) / 1000000) +
253e28a4053SRui Paulo 		50 /* FIX: proper SIFS + ACK duration */;
254e28a4053SRui Paulo 
255e28a4053SRui Paulo 	/* unsigned binary number with an implicit binary point after the
256e28a4053SRui Paulo 	 * leftmost 3 bits, i.e., 0x2000 = 1.0 */
257e28a4053SRui Paulo 	surplus = le_to_host16(tspec->surplus_bandwidth_allowance);
258e28a4053SRui Paulo 	if (surplus <= 0x2000) {
259e28a4053SRui Paulo 		wpa_printf(MSG_DEBUG, "WMM: Surplus Bandwidth Allowance not "
260e28a4053SRui Paulo 			   "greater than unity");
261e28a4053SRui Paulo 		return WMM_ADDTS_STATUS_INVALID_PARAMETERS;
262e28a4053SRui Paulo 	}
263e28a4053SRui Paulo 
26485732ac8SCy Schubert 	medium_time = (u64) surplus * pps * duration / 0x2000;
26585732ac8SCy Schubert 	wpa_printf(MSG_DEBUG, "WMM: Estimated medium time: %lu",
26685732ac8SCy Schubert 		   (unsigned long) medium_time);
267e28a4053SRui Paulo 
268e28a4053SRui Paulo 	/*
269e28a4053SRui Paulo 	 * TODO: store list of granted (and still active) TSPECs and check
270e28a4053SRui Paulo 	 * whether there is available medium time for this request. For now,
271e28a4053SRui Paulo 	 * just refuse requests that would by themselves take very large
272e28a4053SRui Paulo 	 * portion of the available bandwidth.
273e28a4053SRui Paulo 	 */
274e28a4053SRui Paulo 	if (medium_time > 750000) {
275e28a4053SRui Paulo 		wpa_printf(MSG_DEBUG, "WMM: Refuse TSPEC request for over "
276e28a4053SRui Paulo 			   "75%% of available bandwidth");
277e28a4053SRui Paulo 		return WMM_ADDTS_STATUS_REFUSED;
278e28a4053SRui Paulo 	}
279e28a4053SRui Paulo 
280e28a4053SRui Paulo 	/* Convert to 32 microseconds per second unit */
281e28a4053SRui Paulo 	tspec->medium_time = host_to_le16(medium_time / 32);
282e28a4053SRui Paulo 
283e28a4053SRui Paulo 	return WMM_ADDTS_STATUS_ADMISSION_ACCEPTED;
284e28a4053SRui Paulo }
285e28a4053SRui Paulo 
286e28a4053SRui Paulo 
wmm_addts_req(struct hostapd_data * hapd,const struct ieee80211_mgmt * mgmt,const struct wmm_tspec_element * tspec,size_t len)287e28a4053SRui Paulo static void wmm_addts_req(struct hostapd_data *hapd,
288e28a4053SRui Paulo 			  const struct ieee80211_mgmt *mgmt,
289*c1d255d3SCy Schubert 			  const struct wmm_tspec_element *tspec, size_t len)
290e28a4053SRui Paulo {
291e28a4053SRui Paulo 	const u8 *end = ((const u8 *) mgmt) + len;
292e28a4053SRui Paulo 	int res;
293*c1d255d3SCy Schubert 	struct wmm_tspec_element tspec_resp;
294e28a4053SRui Paulo 
295e28a4053SRui Paulo 	if ((const u8 *) (tspec + 1) > end) {
296e28a4053SRui Paulo 		wpa_printf(MSG_DEBUG, "WMM: TSPEC overflow in ADDTS Request");
297e28a4053SRui Paulo 		return;
298e28a4053SRui Paulo 	}
299e28a4053SRui Paulo 
300e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "WMM: ADDTS Request (Dialog Token %d) for TSPEC "
301e28a4053SRui Paulo 		   "from " MACSTR,
302e28a4053SRui Paulo 		   mgmt->u.action.u.wmm_action.dialog_token,
303e28a4053SRui Paulo 		   MAC2STR(mgmt->sa));
304e28a4053SRui Paulo 
305*c1d255d3SCy Schubert 	os_memcpy(&tspec_resp, tspec, sizeof(struct wmm_tspec_element));
306*c1d255d3SCy Schubert 	res = wmm_process_tspec(&tspec_resp);
307e28a4053SRui Paulo 	wpa_printf(MSG_DEBUG, "WMM: ADDTS processing result: %d", res);
308e28a4053SRui Paulo 
309*c1d255d3SCy Schubert 	wmm_send_action(hapd, mgmt->sa, &tspec_resp, WMM_ACTION_CODE_ADDTS_RESP,
310e28a4053SRui Paulo 			mgmt->u.action.u.wmm_action.dialog_token, res);
311e28a4053SRui Paulo }
312e28a4053SRui Paulo 
313e28a4053SRui Paulo 
hostapd_wmm_action(struct hostapd_data * hapd,const struct ieee80211_mgmt * mgmt,size_t len)314e28a4053SRui Paulo void hostapd_wmm_action(struct hostapd_data *hapd,
315e28a4053SRui Paulo 			const struct ieee80211_mgmt *mgmt, size_t len)
316e28a4053SRui Paulo {
317e28a4053SRui Paulo 	int action_code;
318e28a4053SRui Paulo 	int left = len - IEEE80211_HDRLEN - 4;
319e28a4053SRui Paulo 	const u8 *pos = ((const u8 *) mgmt) + IEEE80211_HDRLEN + 4;
320e28a4053SRui Paulo 	struct ieee802_11_elems elems;
321e28a4053SRui Paulo 	struct sta_info *sta = ap_get_sta(hapd, mgmt->sa);
322e28a4053SRui Paulo 
323e28a4053SRui Paulo 	/* check that the request comes from a valid station */
324e28a4053SRui Paulo 	if (!sta ||
325e28a4053SRui Paulo 	    (sta->flags & (WLAN_STA_ASSOC | WLAN_STA_WMM)) !=
326e28a4053SRui Paulo 	    (WLAN_STA_ASSOC | WLAN_STA_WMM)) {
327e28a4053SRui Paulo 		hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
328e28a4053SRui Paulo 			       HOSTAPD_LEVEL_DEBUG,
329e28a4053SRui Paulo 			       "wmm action received is not from associated wmm"
330e28a4053SRui Paulo 			       " station");
331e28a4053SRui Paulo 		/* TODO: respond with action frame refused status code */
332e28a4053SRui Paulo 		return;
333e28a4053SRui Paulo 	}
334e28a4053SRui Paulo 
335325151a3SRui Paulo 	if (left < 0)
336325151a3SRui Paulo 		return; /* not a valid WMM Action frame */
337325151a3SRui Paulo 
338e28a4053SRui Paulo 	/* extract the tspec info element */
339e28a4053SRui Paulo 	if (ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed) {
340e28a4053SRui Paulo 		hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
341e28a4053SRui Paulo 			       HOSTAPD_LEVEL_DEBUG,
342e28a4053SRui Paulo 			       "hostapd_wmm_action - could not parse wmm "
343e28a4053SRui Paulo 			       "action");
344e28a4053SRui Paulo 		/* TODO: respond with action frame invalid parameters status
345e28a4053SRui Paulo 		 * code */
346e28a4053SRui Paulo 		return;
347e28a4053SRui Paulo 	}
348e28a4053SRui Paulo 
349e28a4053SRui Paulo 	if (!elems.wmm_tspec ||
350e28a4053SRui Paulo 	    elems.wmm_tspec_len != (sizeof(struct wmm_tspec_element) - 2)) {
351e28a4053SRui Paulo 		hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
352e28a4053SRui Paulo 			       HOSTAPD_LEVEL_DEBUG,
353e28a4053SRui Paulo 			       "hostapd_wmm_action - missing or wrong length "
354e28a4053SRui Paulo 			       "tspec");
355e28a4053SRui Paulo 		/* TODO: respond with action frame invalid parameters status
356e28a4053SRui Paulo 		 * code */
357e28a4053SRui Paulo 		return;
358e28a4053SRui Paulo 	}
359e28a4053SRui Paulo 
360e28a4053SRui Paulo 	/* TODO: check the request is for an AC with ACM set, if not, refuse
361e28a4053SRui Paulo 	 * request */
362e28a4053SRui Paulo 
363e28a4053SRui Paulo 	action_code = mgmt->u.action.u.wmm_action.action_code;
364e28a4053SRui Paulo 	switch (action_code) {
365e28a4053SRui Paulo 	case WMM_ACTION_CODE_ADDTS_REQ:
366e28a4053SRui Paulo 		wmm_addts_req(hapd, mgmt, (struct wmm_tspec_element *)
367e28a4053SRui Paulo 			      (elems.wmm_tspec - 2), len);
368e28a4053SRui Paulo 		return;
369e28a4053SRui Paulo #if 0
370e28a4053SRui Paulo 	/* TODO: needed for client implementation */
371e28a4053SRui Paulo 	case WMM_ACTION_CODE_ADDTS_RESP:
372e28a4053SRui Paulo 		wmm_setup_request(hapd, mgmt, len);
373e28a4053SRui Paulo 		return;
374e28a4053SRui Paulo 	/* TODO: handle station teardown requests */
375e28a4053SRui Paulo 	case WMM_ACTION_CODE_DELTS:
376e28a4053SRui Paulo 		wmm_teardown(hapd, mgmt, len);
377e28a4053SRui Paulo 		return;
378e28a4053SRui Paulo #endif
379e28a4053SRui Paulo 	}
380e28a4053SRui Paulo 
381e28a4053SRui Paulo 	hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
382e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
383e28a4053SRui Paulo 		       "hostapd_wmm_action - unknown action code %d",
384e28a4053SRui Paulo 		       action_code);
385e28a4053SRui Paulo }
386