ath9k: Add p2p go NoA attribute
[cascardo/linux.git] / drivers / net / wireless / ath / ath9k / beacon.c
index bd9e634..85a40d7 100644 (file)
@@ -80,7 +80,7 @@ static void ath9k_beacon_setup(struct ath_softc *sc, struct ieee80211_vif *vif,
        u8 chainmask = ah->txchainmask;
        u8 rate = 0;
 
-       sband = &common->sbands[common->hw->conf.chandef.chan->band];
+       sband = &common->sbands[sc->cur_chandef.chan->band];
        rate = sband->bitrates[rateidx].hw_value;
        if (vif->bss_conf.use_short_preamble)
                rate |= sband->bitrates[rateidx].hw_value_short;
@@ -108,6 +108,40 @@ static void ath9k_beacon_setup(struct ath_softc *sc, struct ieee80211_vif *vif,
        ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
 }
 
+static void ath9k_beacon_add_noa(struct ath_softc *sc, struct ath_vif *avp,
+                                struct sk_buff *skb)
+{
+       static const u8 noa_ie_hdr[] = {
+               WLAN_EID_VENDOR_SPECIFIC,       /* type */
+               0,                              /* length */
+               0x50, 0x6f, 0x9a,               /* WFA OUI */
+               0x09,                           /* P2P subtype */
+               0x0c,                           /* Notice of Absence */
+               0x00,                           /* LSB of little-endian len */
+               0x00,                           /* MSB of little-endian len */
+       };
+
+       struct ieee80211_p2p_noa_attr *noa;
+       int noa_len = 2 + sizeof(struct ieee80211_p2p_noa_desc);
+       u8 *hdr;
+
+       if (!avp->offchannel_duration)
+               return;
+
+       hdr = skb_put(skb, sizeof(noa_ie_hdr));
+       memcpy(hdr, noa_ie_hdr, sizeof(noa_ie_hdr));
+       hdr[1] = sizeof(noa_ie_hdr) + noa_len - 2;
+       hdr[7] = noa_len;
+
+       noa = (void *) skb_put(skb, noa_len);
+       memset(noa, 0, noa_len);
+
+       noa->index = avp->noa_index;
+       noa->desc[0].count = 1;
+       noa->desc[0].duration = cpu_to_le32(avp->offchannel_duration);
+       noa->desc[0].start_time = cpu_to_le32(avp->offchannel_start);
+}
+
 static struct ath_buf *ath9k_beacon_generate(struct ieee80211_hw *hw,
                                             struct ieee80211_vif *vif)
 {
@@ -155,6 +189,9 @@ static struct ath_buf *ath9k_beacon_generate(struct ieee80211_hw *hw,
                hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
        }
 
+       if (vif->p2p)
+               ath9k_beacon_add_noa(sc, avp, skb);
+
        bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
                                         skb->len, DMA_TO_DEVICE);
        if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
@@ -249,7 +286,7 @@ void ath9k_beacon_remove_slot(struct ath_softc *sc, struct ieee80211_vif *vif)
 static int ath9k_beacon_choose_slot(struct ath_softc *sc)
 {
        struct ath_common *common = ath9k_hw_common(sc->sc_ah);
-       struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
+       struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon;
        u16 intval;
        u32 tsftu;
        u64 tsf;
@@ -277,8 +314,8 @@ static int ath9k_beacon_choose_slot(struct ath_softc *sc)
 static void ath9k_set_tsfadjust(struct ath_softc *sc, struct ieee80211_vif *vif)
 {
        struct ath_common *common = ath9k_hw_common(sc->sc_ah);
-       struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
        struct ath_vif *avp = (void *)vif->drv_priv;
+       struct ath_beacon_config *cur_conf = &avp->chanctx->beacon;
        u32 tsfadjust;
 
        if (avp->av_bslot == 0)
@@ -374,12 +411,19 @@ void ath9k_beacon_tasklet(unsigned long data)
        vif = sc->beacon.bslot[slot];
 
        /* EDMA devices check that in the tx completion function. */
-       if (!edma && ath9k_csa_is_finished(sc, vif))
-               return;
+       if (!edma) {
+               if (sc->sched.beacon_pending)
+                       ath_chanctx_event(sc, NULL,
+                                         ATH_CHANCTX_EVENT_BEACON_SENT);
+
+               if (ath9k_csa_is_finished(sc, vif))
+                       return;
+       }
 
        if (!vif || !vif->bss_conf.enable_beacon)
                return;
 
+       ath_chanctx_event(sc, vif, ATH_CHANCTX_EVENT_BEACON_PREPARE);
        bf = ath9k_beacon_generate(sc->hw, vif);
 
        if (sc->beacon.bmisscnt != 0) {
@@ -500,7 +544,6 @@ static bool ath9k_allow_beacon_config(struct ath_softc *sc,
                                      struct ieee80211_vif *vif)
 {
        struct ath_common *common = ath9k_hw_common(sc->sc_ah);
-       struct ath_vif *avp = (void *)vif->drv_priv;
 
        if (sc->sc_ah->opmode == NL80211_IFTYPE_AP) {
                if ((vif->type != NL80211_IFTYPE_AP) ||
@@ -514,7 +557,7 @@ static bool ath9k_allow_beacon_config(struct ath_softc *sc,
        if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) {
                if ((vif->type == NL80211_IFTYPE_STATION) &&
                    test_bit(ATH_OP_BEACONS, &common->op_flags) &&
-                   !avp->primary_sta_vif) {
+                   vif != sc->cur_chan->primary_sta) {
                        ath_dbg(common, CONFIG,
                                "Beacon already configured for a station interface\n");
                        return false;
@@ -525,10 +568,11 @@ static bool ath9k_allow_beacon_config(struct ath_softc *sc,
 }
 
 static void ath9k_cache_beacon_config(struct ath_softc *sc,
+                                     struct ath_chanctx *ctx,
                                      struct ieee80211_bss_conf *bss_conf)
 {
        struct ath_common *common = ath9k_hw_common(sc->sc_ah);
-       struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
+       struct ath_beacon_config *cur_conf = &ctx->beacon;
 
        ath_dbg(common, BEACON,
                "Caching beacon data for BSS: %pM\n", bss_conf->bssid);
@@ -537,8 +581,6 @@ static void ath9k_cache_beacon_config(struct ath_softc *sc,
        cur_conf->dtim_period = bss_conf->dtim_period;
        cur_conf->dtim_count = 1;
        cur_conf->ibss_creator = bss_conf->ibss_creator;
-       cur_conf->bmiss_timeout =
-               ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
 
        /*
         * It looks like mac80211 may end up using beacon interval of zero in
@@ -549,6 +591,9 @@ static void ath9k_cache_beacon_config(struct ath_softc *sc,
        if (cur_conf->beacon_interval == 0)
                cur_conf->beacon_interval = 100;
 
+       cur_conf->bmiss_timeout =
+               ATH_DEFAULT_BMISS_LIMIT * cur_conf->beacon_interval;
+
        /*
         * We don't parse dtim period from mac80211 during the driver
         * initialization as it breaks association with hidden-ssid
@@ -563,20 +608,29 @@ void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
                         u32 changed)
 {
        struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
-       struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
         struct ath_hw *ah = sc->sc_ah;
         struct ath_common *common = ath9k_hw_common(ah);
+       struct ath_vif *avp = (void *)vif->drv_priv;
+       struct ath_chanctx *ctx = avp->chanctx;
+       struct ath_beacon_config *cur_conf;
        unsigned long flags;
        bool skip_beacon = false;
 
+       if (!ctx)
+               return;
+
+       cur_conf = &avp->chanctx->beacon;
        if (vif->type == NL80211_IFTYPE_AP)
                ath9k_set_tsfadjust(sc, vif);
 
        if (!ath9k_allow_beacon_config(sc, vif))
                return;
 
-       if (sc->sc_ah->opmode == NL80211_IFTYPE_STATION) {
-               ath9k_cache_beacon_config(sc, bss_conf);
+       if (vif->type == NL80211_IFTYPE_STATION) {
+               ath9k_cache_beacon_config(sc, ctx, bss_conf);
+               if (ctx != sc->cur_chan)
+                       return;
+
                ath9k_set_beacon(sc);
                set_bit(ATH_OP_BEACONS, &common->op_flags);
                return;
@@ -592,10 +646,13 @@ void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
                        cur_conf->enable_beacon = false;
                } else if (bss_conf->enable_beacon) {
                        cur_conf->enable_beacon = true;
-                       ath9k_cache_beacon_config(sc, bss_conf);
+                       ath9k_cache_beacon_config(sc, ctx, bss_conf);
                }
        }
 
+       if (ctx != sc->cur_chan)
+               return;
+
        /*
         * Configure the HW beacon registers only when we have a valid
         * beacon interval.
@@ -630,7 +687,7 @@ void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
 void ath9k_set_beacon(struct ath_softc *sc)
 {
        struct ath_common *common = ath9k_hw_common(sc->sc_ah);
-       struct ath_beacon_config *cur_conf = &sc->cur_beacon_conf;
+       struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon;
 
        switch (sc->sc_ah->opmode) {
        case NL80211_IFTYPE_AP: