Documentation/cImages/baseline-2.3.ndz: patch-02-adhoc-beacon-6.diff

File patch-02-adhoc-beacon-6.diff, 6.1 KB (added by mcgrof, 17 years ago)

Generate beacons faster after merge

  • madwifi-0.9.3.

    Ad-hoc mode beacons are not transmitted for a while after a merge
    with another network.
    
    http://madwifi.org/ticket/1033
    
    This patch was rebased for madwifi-0.9.3.1
    
    Signed-Off by: Luis Rodriguez <mcgrof@winlab.rutgers.edu>
    
    diff -Naur madwifi-0.9.3.1/ath/if_ath.c madwifi-0.9.3.1-adhoc-beacon5/ath/if_ath.c
    old new  
    44204420    struct ieee80211com *ic = &sc->sc_ic;
    44214421    struct ath_hal *ah = sc->sc_ah;
    44224422    struct ieee80211_node *ni;
    4423     u_int32_t nexttbtt, intval;
     4423    u_int32_t nexttbtt = 0;
     4424    u_int32_t intval;
     4425    u_int64_t tsf, hw_tsf;
     4426    u_int32_t tsftu, hw_tsftu;
     4427    int should_reset_tsf = 0;
    44244428
    44254429    if (vap == NULL)
    44264430        vap = TAILQ_FIRST(&ic->ic_vaps);   /* XXX */
    44274431
    44284432    ni = vap->iv_bss;
    44294433
    4430     /* extract tstamp from last beacon and convert to TU */
    4431     nexttbtt = TSF_TO_TU(LE_READ_4(ni->ni_tstamp.data + 4),
    4432                  LE_READ_4(ni->ni_tstamp.data));
     4434    hw_tsf = ath_hal_gettsf64(ah);
     4435    tsf = le64_to_cpu(ni->ni_tstamp.tsf);
     4436    hw_tsftu = hw_tsf >> 10;
     4437    tsftu = tsf >> 10;
     4438
     4439    /* we should reset hw TSF only once, so we increment
     4440       ni_tstamp.tsf to avoid resetting the hw TSF multiple
     4441       times */
     4442
     4443    if (tsf == 0) {
     4444        should_reset_tsf = 1;
     4445        ni->ni_tstamp.tsf = cpu_to_le64(1);
     4446    }
     4447
    44334448    /* XXX conditionalize multi-bss support? */
    44344449    if (ic->ic_opmode == IEEE80211_M_HOSTAP) {
    44354450        /*
     
    44434458        if (sc->sc_stagbeacons)
    44444459            intval /= ATH_BCBUF;    /* for staggered beacons */
    44454460        if ((sc->sc_nostabeacons) &&
    4446             (vap->iv_opmode == IEEE80211_M_HOSTAP))
    4447             nexttbtt = 0;
     4461            (vap->iv_opmode == IEEE80211_M_HOSTAP))
     4462            should_reset_tsf = 1;
    44484463    } else
    44494464        intval = ni->ni_intval & HAL_BEACON_PERIOD;
    4450     if (nexttbtt == 0)      /* e.g. for ap mode */
     4465
     4466#define FUDGE   2
     4467    sc->sc_syncbeacon = 0;
     4468    if (should_reset_tsf) {
     4469
     4470        /* We just created the interface and TSF will be reset to
     4471           zero, so next beacon will be sent at the next intval
     4472           time */
     4473
    44514474        nexttbtt = intval;
    4452     else if (intval)        /* NB: can be 0 for monitor mode */
    4453         nexttbtt = roundup(nexttbtt, intval);
    4454     DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt %u intval %u (%u)\n",
    4455         __func__, nexttbtt, intval, ni->ni_intval);
     4475    } else if (intval) {    /* NB: can be 0 for monitor mode */
     4476        if (tsf == 1) {
     4477   
     4478            /* We do not receive any beacons or probe response. Since
     4479               a beacon should be sent every 'intval' ms, we compute
     4480               the next beacon timestamp using the hardware TSF. We
     4481               ensure that it is at least FUDGE ms ahead of the
     4482               current TSF. Otherwise, we use the next beacon
     4483               timestamp again */
     4484
     4485            nexttbtt = roundup(hw_tsftu +1, intval);
     4486            while (nexttbtt <= hw_tsftu + FUDGE) {
     4487                nexttbtt += intval;
     4488            }
     4489        } else {
     4490            if (tsf > hw_tsf) {
     4491
     4492            /* We do receive a beacon from someone else in the past,
     4493               but the hw TSF has not been updated (otherwise we
     4494               would have tsf >= hw_tsf). Since we cannot use the
     4495               hardware TSF, we will do nothing and wait for the
     4496               next beacon. In order to do so, we set sc->syncbeacon
     4497               again */
     4498
     4499                sc->sc_syncbeacon = 1;
     4500                goto ath_beacon_config_debug;
     4501            } else {
     4502                /* We do receive a beacon in the past, normal case. We
     4503                   make sure that the timestamp is at least FUDGE ms
     4504                   ahead of the hardware TSF */
     4505
     4506                nexttbtt = tsftu + intval;
     4507                while (nexttbtt <= hw_tsftu + FUDGE) {
     4508                    nexttbtt += intval;
     4509                }
     4510            }
     4511        }
     4512    }
     4513
    44564514    if (ic->ic_opmode == IEEE80211_M_STA && !(sc->sc_nostabeacons)) {
    44574515        HAL_BEACON_STATE bs;
    4458         u_int64_t tsf;
    4459         u_int32_t tsftu;
    44604516        int dtimperiod, dtimcount;
    44614517        int cfpperiod, cfpcount;
    44624518
     
    44724528            dtimcount = 0;      /* XXX? */
    44734529        cfpperiod = 1;          /* NB: no PCF support yet */
    44744530        cfpcount = 0;
    4475 #define FUDGE   2
    44764531        /*
    44774532         * Pull nexttbtt forward to reflect the current
    44784533         * TSF and calculate dtim+cfp state for the result.
    44794534         */
    4480         tsf = ath_hal_gettsf64(ah);
    4481         tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
     4535        nexttbtt = tsftu;
     4536        if (nexttbtt == 0)      /* e.g. for ap mode */
     4537            nexttbtt = intval;
    44824538        do {
    44834539            nexttbtt += intval;
    44844540            if (--dtimcount < 0) {
     
    44864542                if (--cfpcount < 0)
    44874543                    cfpcount = cfpperiod - 1;
    44884544            }
    4489         } while (nexttbtt < tsftu);
     4545        } while (nexttbtt < hw_tsftu + FUDGE);
    44904546#undef FUDGE
    44914547        memset(&bs, 0, sizeof(bs));
    44924548        bs.bs_intval = intval;
     
    45384594        DPRINTF(sc, ATH_DEBUG_BEACON,
    45394595            "%s: tsf %llu tsf:tu %u intval %u nexttbtt %u dtim %u nextdtim %u bmiss %u sleep %u cfp:period %u maxdur %u next %u timoffset %u\n"
    45404596            , __func__
    4541             , (long long) tsf, tsftu
     4597            , (long long) hw_tsf, hw_tsftu
    45424598            , bs.bs_intval
    45434599            , bs.bs_nexttbtt
    45444600            , bs.bs_dtimperiod
     
    45574613        ath_hal_intrset(ah, sc->sc_imask);
    45584614    } else {
    45594615        ath_hal_intrset(ah, 0);
    4560         if (nexttbtt == intval)
     4616        if (should_reset_tsf)
    45614617            intval |= HAL_BEACON_RESET_TSF;
    45624618        if (ic->ic_opmode == IEEE80211_M_IBSS) {
    45634619            /*
     
    45944650        if (ic->ic_opmode == IEEE80211_M_IBSS && sc->sc_hasveol)
    45954651            ath_beacon_start_adhoc(sc, vap);
    45964652    }
    4597     sc->sc_syncbeacon = 0;
    45984653#undef TSF_TO_TU
     4654
     4655    ath_beacon_config_debug:
     4656
     4657    /* we print all debug messages here, in order to preserve the
     4658       time critical aspect of this function */
     4659
     4660    DPRINTF(sc, ATH_DEBUG_BEACON,
     4661        "%s: ni=%p tsf=%llu hw_tsf=%llu tsftu=%u hw_tsftu=%u\n",
     4662        __func__, ni, tsf, hw_tsf, tsftu, hw_tsftu);
     4663
     4664    if (should_reset_tsf) {
     4665        /* we just created the interface */
     4666        DPRINTF(sc, ATH_DEBUG_BEACON, "%s: first beacon\n",__func__);
     4667    } else {
     4668        if (tsf == 1) {
     4669            /* we do not receive any beacons or probe response */
     4670            DPRINTF(sc, ATH_DEBUG_BEACON,
     4671                "%s: no beacon received...\n",__func__);
     4672        } else {
     4673            if (tsf > hw_tsf) {
     4674                /* we do receive a beacon and the hw TSF has not been updated */
     4675                DPRINTF(sc, ATH_DEBUG_BEACON,
     4676                    "%s: beacon received, but TSF is incorrect\n",__func__);
     4677            } else {
     4678                /* we do receive a beacon in the past, normal case */
     4679                DPRINTF(sc, ATH_DEBUG_BEACON,
     4680                    "%s: beacon received, TSF is correct\n",__func__);
     4681            }
     4682        }
     4683    }
     4684
     4685    DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt=%u intval=%u\n",
     4686        __func__,nexttbtt, intval & HAL_BEACON_PERIOD);
    45994687}
    46004688
    46014689static int