123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- #include "includes.h"
- #include "hostapd.h"
- #include "ieee802_11.h"
- #include "wme.h"
- #include "sta_info.h"
- #include "driver_i.h"
- static inline u8 wmm_aci_aifsn(int aifsn, int acm, int aci)
- {
- u8 ret;
- ret = (aifsn << WMM_AC_AIFNS_SHIFT) & WMM_AC_AIFSN_MASK;
- if (acm)
- ret |= WMM_AC_ACM;
- ret |= (aci << WMM_AC_ACI_SHIFT) & WMM_AC_ACI_MASK;
- return ret;
- }
- static inline u8 wmm_ecw(int ecwmin, int ecwmax)
- {
- return ((ecwmin << WMM_AC_ECWMIN_SHIFT) & WMM_AC_ECWMIN_MASK) |
- ((ecwmax << WMM_AC_ECWMAX_SHIFT) & WMM_AC_ECWMAX_MASK);
- }
- u8 * hostapd_eid_wmm(struct hostapd_data *hapd, u8 *eid)
- {
- u8 *pos = eid;
- struct wmm_parameter_element *wmm =
- (struct wmm_parameter_element *) (pos + 2);
- int e;
- if (!hapd->conf->wmm_enabled)
- return eid;
- eid[0] = WLAN_EID_VENDOR_SPECIFIC;
- wmm->oui[0] = 0x00;
- wmm->oui[1] = 0x50;
- wmm->oui[2] = 0xf2;
- wmm->oui_type = WMM_OUI_TYPE;
- wmm->oui_subtype = WMM_OUI_SUBTYPE_PARAMETER_ELEMENT;
- wmm->version = WMM_VERSION;
- wmm->qos_info = hapd->parameter_set_count & 0xf;
-
- for (e = 0; e < 4; e++) {
- struct wmm_ac_parameter *ac = &wmm->ac[e];
- struct hostapd_wmm_ac_params *acp =
- &hapd->iconf->wmm_ac_params[e];
- ac->aci_aifsn = wmm_aci_aifsn(acp->aifs,
- acp->admission_control_mandatory,
- e);
- ac->cw = wmm_ecw(acp->cwmin, acp->cwmax);
- ac->txop_limit = host_to_le16(acp->txop_limit);
- }
- pos = (u8 *) (wmm + 1);
- eid[1] = pos - eid - 2;
- return pos;
- }
- int hostapd_eid_wmm_valid(struct hostapd_data *hapd, u8 *eid, size_t len)
- {
- struct wmm_information_element *wmm;
- wpa_hexdump(MSG_MSGDUMP, "WMM IE", eid, len);
- if (len < sizeof(struct wmm_information_element)) {
- wpa_printf(MSG_DEBUG, "Too short WMM IE (len=%lu)",
- (unsigned long) len);
- return -1;
- }
- wmm = (struct wmm_information_element *) eid;
- wpa_printf(MSG_DEBUG, "Validating WMM IE: OUI %02x:%02x:%02x "
- "OUI type %d OUI sub-type %d version %d QoS info 0x%x",
- wmm->oui[0], wmm->oui[1], wmm->oui[2], wmm->oui_type,
- wmm->oui_subtype, wmm->version, wmm->qos_info);
- if (wmm->oui_subtype != WMM_OUI_SUBTYPE_INFORMATION_ELEMENT ||
- wmm->version != WMM_VERSION) {
- wpa_printf(MSG_DEBUG, "Unsupported WMM IE Subtype/Version");
- return -1;
- }
- return 0;
- }
- int hostapd_wmm_sta_config(struct hostapd_data *hapd, struct sta_info *sta)
- {
-
- if (sta->flags & WLAN_STA_WMM)
- hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- WLAN_STA_WMM, ~0);
- else
- hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
- 0, ~WLAN_STA_WMM);
- return 0;
- }
- static void 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)
- {
- u8 buf[256];
- struct ieee80211_mgmt *m = (struct ieee80211_mgmt *) buf;
- struct wmm_tspec_element *t = (struct wmm_tspec_element *)
- m->u.action.u.wmm_action.variable;
- int len;
- hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_DEBUG,
- "action response - reason %d", status_code);
- os_memset(buf, 0, sizeof(buf));
- m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
- WLAN_FC_STYPE_ACTION);
- os_memcpy(m->da, addr, ETH_ALEN);
- os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
- os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
- m->u.action.category = WLAN_ACTION_WMM;
- m->u.action.u.wmm_action.action_code = action_code;
- m->u.action.u.wmm_action.dialog_token = dialogue_token;
- m->u.action.u.wmm_action.status_code = status_code;
- os_memcpy(t, tspec, sizeof(struct wmm_tspec_element));
- len = ((u8 *) (t + 1)) - buf;
- if (hostapd_send_mgmt_frame(hapd, m, len, 0) < 0)
- perror("wmm_send_action: send");
- }
- static double wmm_frame_exchange_time(int bytes, int data_rate, int encryption,
- int cts_protection)
- {
-
-
-
-
-
- return (bytes + 400) * 8.0 / data_rate;
- }
- static void wmm_addts_req(struct hostapd_data *hapd,
- struct ieee80211_mgmt *mgmt,
- struct wmm_tspec_element *tspec, size_t len)
- {
-
- double medium_time, pps;
-
- pps = (le_to_host32(tspec->mean_data_rate) / 8.0) /
- le_to_host16(tspec->nominal_msdu_size);
- medium_time = (le_to_host16(tspec->surplus_bandwidth_allowance) / 8) *
- pps *
- wmm_frame_exchange_time(le_to_host16(tspec->nominal_msdu_size),
- le_to_host32(tspec->minimum_phy_rate),
- 0, 0);
- tspec->medium_time = host_to_le16(medium_time * 1000000.0 / 32.0);
- wmm_send_action(hapd, mgmt->sa, tspec, WMM_ACTION_CODE_ADDTS_RESP,
- mgmt->u.action.u.wmm_action.dialog_token,
- WMM_ADDTS_STATUS_ADMISSION_ACCEPTED);
- }
- void hostapd_wmm_action(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
- size_t len)
- {
- int action_code;
- int left = len - IEEE80211_HDRLEN - 4;
- u8 *pos = ((u8 *) mgmt) + IEEE80211_HDRLEN + 4;
- struct ieee802_11_elems elems;
- struct sta_info *sta = ap_get_sta(hapd, mgmt->sa);
-
- if (!sta ||
- (sta->flags & (WLAN_STA_ASSOC | WLAN_STA_WMM)) !=
- (WLAN_STA_ASSOC | WLAN_STA_WMM)) {
- hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_DEBUG,
- "wmm action received is not from associated wmm"
- " station");
-
- return;
- }
-
- if (ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed) {
- hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_DEBUG,
- "hostapd_wmm_action - could not parse wmm "
- "action");
-
- return;
- }
- if (!elems.wmm_tspec ||
- elems.wmm_tspec_len != (sizeof(struct wmm_tspec_element) - 2)) {
- hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_DEBUG,
- "hostapd_wmm_action - missing or wrong length "
- "tspec");
-
- return;
- }
-
- action_code = mgmt->u.action.u.wmm_action.action_code;
- switch (action_code) {
- case WMM_ACTION_CODE_ADDTS_REQ:
- wmm_addts_req(hapd, mgmt, (struct wmm_tspec_element *)
- (elems.wmm_tspec - 2), len);
- return;
- #if 0
-
- case WMM_ACTION_CODE_ADDTS_RESP:
- wmm_setup_request(hapd, mgmt, len);
- return;
-
- case WMM_ACTION_CODE_DELTS:
- wmm_teardown(hapd, mgmt, len);
- return;
- #endif
- }
- hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_DEBUG,
- "hostapd_wmm_action - unknown action code %d",
- action_code);
- }
|