^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2004, Instant802 Networks, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 2013-2014 Intel Mobile Communications GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/mac80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "ieee80211_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "wme.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* Default mapping in classifier to work with default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * queue setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) const int ieee802_1d_to_ac[8] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) IEEE80211_AC_BE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) IEEE80211_AC_BK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) IEEE80211_AC_BK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) IEEE80211_AC_BE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) IEEE80211_AC_VI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) IEEE80211_AC_VI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) IEEE80211_AC_VO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) IEEE80211_AC_VO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static int wme_downgrade_ac(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) switch (skb->priority) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) skb->priority = 5; /* VO -> VI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) skb->priority = 3; /* VI -> BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) skb->priority = 2; /* BE -> BK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * ieee80211_fix_reserved_tid - return the TID to use if this one is reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @tid: the assumed-reserved TID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Returns: the alternative TID to use, or 0 on error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static inline u8 ieee80211_fix_reserved_tid(u8 tid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) switch (tid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) case 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) case 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) case 7:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static u16 ieee80211_downgrade_queue(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct sta_info *sta, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* in case we are a client verify acm is not set for this ac */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) while (sdata->wmm_acm & BIT(skb->priority)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int ac = ieee802_1d_to_ac[skb->priority];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (ifmgd->tx_tspec[ac].admitted_time &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) skb->priority == ifmgd->tx_tspec[ac].up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (wme_downgrade_ac(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * This should not really happen. The AP has marked all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * lower ACs to require admission control which is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * a reasonable configuration. Allow the frame to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * transmitted using AC_BK as a workaround.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* Check to see if this is a reserved TID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (sta && sta->reserved_tid == skb->priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) skb->priority = ieee80211_fix_reserved_tid(skb->priority);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* look up which queue to use for frames with this 1d tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return ieee802_1d_to_ac[skb->priority];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* Indicate which queue to use for this fully formed 802.11 frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u16 ieee80211_select_queue_80211(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct ieee80211_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u8 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (local->hw.queues < IEEE80211_NUM_ACS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (!ieee80211_is_data(hdr->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) skb->priority = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return ieee802_1d_to_ac[skb->priority];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!ieee80211_is_data_qos(hdr->frame_control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) skb->priority = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return ieee802_1d_to_ac[skb->priority];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) p = ieee80211_get_qos_ctl(hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return ieee80211_downgrade_queue(sdata, NULL, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u16 __ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct sta_info *sta, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct mac80211_qos_map *qos_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) bool qos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* all mesh/ocb stations are required to support WME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) sdata->vif.type == NL80211_IFTYPE_OCB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) qos = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) else if (sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) qos = sta->sta.wme;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) qos = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!qos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) skb->priority = 0; /* required for correct WPA/11i MIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return IEEE80211_AC_BE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (skb->protocol == sdata->control_port_protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) skb->priority = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) goto downgrade;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* use the data classifier to determine what 802.1d tag the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * data frame has */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) qos_map = rcu_dereference(sdata->qos_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) skb->priority = cfg80211_classify8021d(skb, qos_map ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) &qos_map->qos_map : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) downgrade:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return ieee80211_downgrade_queue(sdata, sta, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* Indicate which queue to use. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u16 ieee80211_select_queue(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct sta_info *sta = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) const u8 *ra = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) u16 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* when using iTXQ, we can do this later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (local->ops->wake_tx_queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (local->hw.queues < IEEE80211_NUM_ACS || skb->len < 6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) skb->priority = 0; /* required for correct WPA/11i MIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) sta = rcu_dereference(sdata->u.vlan.sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ra = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ra = sdata->u.wds.remote_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* might be a TDLS station */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) sta = sta_info_get(sdata, skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ra = sdata->u.mgd.bssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ra = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (!sta && ra && !is_multicast_ether_addr(ra))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) sta = sta_info_get(sdata, ra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ret = __ieee80211_select_queue(sdata, sta, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * ieee80211_set_qos_hdr - Fill in the QoS header if there is one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * @sdata: local subif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * @skb: packet to be updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) void ieee80211_set_qos_hdr(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct ieee80211_hdr *hdr = (void *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) u8 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) u8 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (!ieee80211_is_data_qos(hdr->frame_control))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) p = ieee80211_get_qos_ctl(hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* set up the first byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * preserve everything but the TID and ACK policy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * (which we both write here)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) flags = *p & ~(IEEE80211_QOS_CTL_TID_MASK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) IEEE80211_QOS_CTL_ACK_POLICY_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (is_multicast_ether_addr(hdr->addr1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) sdata->noack_map & BIT(tid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) flags |= IEEE80211_QOS_CTL_ACK_POLICY_NOACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) info->flags |= IEEE80211_TX_CTL_NO_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) *p = flags | tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* set up the second byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (ieee80211_vif_is_mesh(&sdata->vif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* preserve RSPI and Mesh PS Level bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) *p &= ((IEEE80211_QOS_CTL_RSPI |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) IEEE80211_QOS_CTL_MESH_PS_LEVEL) >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /* Nulls don't have a mesh header (frame body) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (!ieee80211_is_qos_nullfunc(hdr->frame_control))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) *p |= (IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) *p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }