run-hostap-dinar.diff

Diff from Dinar Talypov - Stefan Sperling, 05/23/2014 09:40 pm

Download (6.3 kB)

if_run.c 19 May 2014 04:16:37 -0000
377 377
void        run_set_basicrates(struct run_softc *);
378 378
void        run_set_leds(struct run_softc *, uint16_t);
379 379
void        run_set_bssid(struct run_softc *, const uint8_t *);
380
#ifndef IEEE80211_STA_ONLY
381
int        run_prepare_beacon(struct run_softc *);
382
#endif
380 383
void        run_set_macaddr(struct run_softc *, const uint8_t *);
381 384
void        run_updateslot(struct ieee80211com *);
382 385
void        run_updateslot_cb(struct run_softc *, void *);
......
542 545
    /* set device capabilities */
543 546
    ic->ic_caps =
544 547
        IEEE80211_C_MONITOR |    /* monitor mode supported */
548
#ifndef IEEE80211_STA_ONLY
549
        IEEE80211_C_IBSS |        /* IBSS mode supported */
550
        IEEE80211_C_HOSTAP |    /* HostAP mode supported */
551
#endif
545 552
        IEEE80211_C_SHPREAMBLE |    /* short preamble supported */
546 553
        IEEE80211_C_SHSLOT |    /* short slot time supported */
547 554
        IEEE80211_C_WEP |        /* WEP */
......
1590 1597
            run_set_basicrates(sc);
1591 1598
            run_set_bssid(sc, ni->ni_bssid);
1592 1599
        }
1600
#ifndef IEEE80211_STA_ONLY
1601
        if (ic->ic_opmode == IEEE80211_M_HOSTAP ||
1602
            ic->ic_opmode == IEEE80211_M_IBSS)
1603
            (void)run_prepare_beacon(sc);
1604
#endif
1593 1605
        if (ic->ic_opmode == IEEE80211_M_STA) {
1594 1606
            /* add BSS entry to the WCID table */
1595 1607
            wcid = RUN_AID2WCID(ni->ni_associd);
......
1693 1705
{
1694 1706
    struct run_cmd_key *cmd = arg;
1695 1707
    struct ieee80211_key *k = &cmd->key;
1708
#ifndef IEEE80211_STA_ONLY
1709
    struct ieee80211com *ic = &sc->sc_ic;
1710
#endif
1696 1711
    uint32_t attr;
1697 1712
    uint16_t base;
1698 1713
    uint8_t mode, wcid, iv[8];
......
1725 1740
    if (k->k_cipher == IEEE80211_CIPHER_TKIP) {
1726 1741
        run_write_region_1(sc, base, k->k_key, 16);
1727
        run_write_region_1(sc, base + 16, &k->k_key[24], 8);
1728
        run_write_region_1(sc, base + 24, &k->k_key[16], 8);
1742
#ifndef IEEE80211_STA_ONLY
1743
        if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
1744
            run_write_region_1(sc, base + 16, &k->k_key[24], 8);
1745
            run_write_region_1(sc, base + 24, &k->k_key[16], 8);
1746
        }
1747
        else
1748
#endif
1749
        {
1750
            run_write_region_1(sc, base + 16, &k->k_key[16], 8);
1751
            run_write_region_1(sc, base + 24, &k->k_key[24], 8);
1752
        }
1729 1753
    } else {
1730 1754
        /* roundup len to 16-bit: XXX fix write_region_1() instead */
1731 1755
        run_write_region_1(sc, base, k->k_key, (k->k_len + 1) & ~1);
......
2211 2235
        *(uint16_t *)wh->i_dur = htole16(dur);
2212 2236
    }
2237
#ifndef IEEE80211_STA_ONLY
2238
    /* ask MAC to insert timestamp into probe responses */
2239
    if ((wh->i_fc[0] &
2240
        (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) ==
2241
        (IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_RESP))
2242
        /* NOTE: beacons do not pass through tx_data() */
2243
        txwi->flags |= RT2860_TX_TS;
2244
#endif
2245

  
2213 2246
#if NBPFILTER > 0
2214 2247
    if (__predict_false(sc->sc_drvbpf != NULL)) {
2215 2248
        struct run_tx_radiotap_header *tap = &sc->sc_txtap;
......
2816 2849
    tmp &= ~0x1fffff;
2817 2850
    tmp |= ic->ic_bss->ni_intval * 16;
2818 2851
    tmp |= RT2860_TSF_TIMER_EN | RT2860_TBTT_TIMER_EN;
2819
    /* local TSF is always updated with remote TSF on beacon reception */
2820
    tmp |= 1 << RT2860_TSF_SYNC_MODE_SHIFT;
2852
    if (ic->ic_opmode == IEEE80211_M_STA) {
2853
        /*
2854
         * Local TSF is always updated with remote TSF on
2855
         * beacon reception
2856
         */
2857
        tmp |= 1 << RT2860_TSF_SYNC_MODE_SHIFT;
2858
    }
2859
#ifndef IEEE80211_STA_ONLY
2860
    else if (ic->ic_opmode == IEEE80211_M_IBSS) {
2861
        tmp |= RT2860_BCN_TX_EN;
2862
        /*
2863
         * Local TSF is updated with remote TSF on beacon reception
2864
         * only if the remote TSF is greater than local TSF.
2865
         */
2866
        tmp |= 2 << RT2860_TSF_SYNC_MODE_SHIFT;
2867
    } else if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
2868
        tmp |= RT2860_BCN_TX_EN;
2869
        /* SYNC with nobody */
2870
        tmp |= 3 << RT2860_TSF_SYNC_MODE_SHIFT;
2871
    }
2872
#endif
2821 2873
    run_write(sc, RT2860_BCN_TIME_CFG, tmp);
2822 2874
}
......
3437 3489
    run_set_region_4(sc, RT2860_SKEY(0, 0), 0, 8 * 32);
3438 3490
    /* clear shared key mode */
3439 3491
    run_set_region_4(sc, RT2860_SKEY_MODE_0_7, 0, 4);
3492
    /* clear Pair-wise key table */
3493
    run_set_region_4(sc, RT2860_PKEY(0), 0, 2048);
3494
    /* clear IV/EIV table */
3495
    run_set_region_4(sc, RT2860_IVEIV(0), 0, 512);
3440 3496
    run_read(sc, RT2860_US_CYC_CNT, &tmp);
3441 3497
    tmp = (tmp & ~0xff) | 0x1e;
......
3574 3630
        run_free_tx_ring(sc, qid);
3575 3631
    run_free_rx_ring(sc);
3576 3632
}
3633

  
3634
#ifndef IEEE80211_STA_ONLY
3635
int
3636
run_prepare_beacon(struct run_softc *sc)
3637
{
3638
    struct ieee80211com *ic = &sc->sc_ic;
3639
    struct rt2860_txwi txwi;
3640
    struct mbuf *m;
3641
    int ridx;
3642

  
3643
    if ((m = ieee80211_beacon_alloc(ic, ic->ic_bss)) == NULL)
3644
        return (ENOBUFS);
3645

  
3646
    memset(&txwi, 0, sizeof (txwi));
3647
    txwi.wcid = 0xff;
3648
    /* length should be multiple of two */
3649
    txwi.len = htole16((m->m_pkthdr.len +1) & ~1);
3650
    /* send beacons at the lowest available rate */
3651
    ridx = (ic->ic_curmode == IEEE80211_MODE_11A) ?
3652
        RT2860_RIDX_OFDM6 : RT2860_RIDX_CCK1;
3653
    txwi.phy = htole16(rt2860_rates[ridx].mcs);
3654
    if (rt2860_rates[ridx].phy == IEEE80211_T_OFDM)
3655
        txwi.phy |= htole16(RT2860_PHY_OFDM);
3656
    txwi.txop = RT2860_TX_TXOP_HT;
3657
    txwi.flags = RT2860_TX_TS;
3658

  
3659
    run_write_region_1(sc, RT2860_BCN_BASE(0),
3660
        (uint8_t *)&txwi, sizeof (txwi));
3661
    run_write_region_1(sc, RT2860_BCN_BASE(0) + sizeof(txwi),
3662
        mtod(m, uint8_t *), (m->m_pkthdr.len + 1) & ~1);
3663

  
3664
    m_freem(m);
3665

  
3666
    return (0);
3667
}
3668
#endif
3577 3669
int
3578 3670
run_activate(struct device *self, int act)