Ticket #1033: adhoc-beacon-4.diff

File adhoc-beacon-4.diff, 5.6 kB (added by benoit.papillault@free.fr, 2 years ago)

replace adhoc-beacon-3.diff. when nexttbtt cannot be computed, it waits for the next beacon

  • ath/if_ath.c

    old new  
    44214421        struct ath_hal *ah = sc->sc_ah; 
    44224422        struct ieee80211_node *ni; 
    44234423        u_int32_t nexttbtt, intval; 
     4424        u_int64_t tsf, hw_tsf; 
     4425        u_int32_t tsftu, hw_tsftu; 
     4426        int should_reset_tsf = 0; 
    44244427 
    44254428        if (vap == NULL) 
    44264429                vap = TAILQ_FIRST(&ic->ic_vaps);   /* XXX */ 
    44274430 
    44284431        ni = vap->iv_bss; 
    44294432 
    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)); 
     4433        hw_tsf = ath_hal_gettsf64(ah); 
     4434        tsf = le64_to_cpu(ni->ni_tstamp.tsf); 
     4435        hw_tsftu = hw_tsf >> 10; 
     4436        tsftu = tsf >> 10; 
     4437 
     4438        /* we should reset hw TSF only once, so we increment 
     4439           ni_tstamp.tsf to avoid resetting the hw TSF multiple 
     4440           times */ 
     4441 
     4442        if (tsf == 0) { 
     4443          should_reset_tsf = 1; 
     4444          ni->ni_tstamp.tsf = cpu_to_le64(tsf+1); 
     4445        } 
     4446 
    44334447        /* XXX conditionalize multi-bss support? */ 
    44344448        if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 
    44354449                /* 
     
    44454459                if ((sc->sc_nostabeacons) && 
    44464460                    (vap->iv_opmode == IEEE80211_M_HOSTAP)) 
    44474461                        nexttbtt = 0; 
     4462 
     4463                /* FIXME : setting nexttbtt to 0 is ignored */ 
    44484464        } else 
    44494465                intval = ni->ni_intval & HAL_BEACON_PERIOD; 
    4450         if (nexttbtt == 0)              /* e.g. for ap mode */ 
    4451                 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); 
     4466 
     4467#define FUDGE   2 
     4468        sc->sc_syncbeacon = 0; 
     4469        if (should_reset_tsf) { 
     4470 
     4471          /* We just created the interface and TSF will be reset to 
     4472             zero, so next beacon will be sent at the next intval 
     4473             time */ 
     4474           
     4475          nexttbtt = intval; 
     4476        } else { 
     4477          if (tsf == 1) { 
     4478             
     4479            /* We do not receive any beacons or probe response. Since 
     4480               a beacon should be sent every 'intval' ms, we compute 
     4481               the next beacon timestamp using the hardware TSF. We 
     4482               ensure that it is at least FUDGE ms ahead of the 
     4483               current TSF. Otherwise, we use the next beacon 
     4484               timestamp again */ 
     4485 
     4486            nexttbtt = roundup(hw_tsftu +1, intval); 
     4487            while (nexttbtt <= hw_tsftu + FUDGE) { 
     4488              nexttbtt += intval; 
     4489            } 
     4490          } else { 
     4491            if (tsf > hw_tsf) { 
     4492 
     4493              /* We do receive a beacon from someone else in the past, 
     4494                 but the hw TSF has not been updated (otherwise we 
     4495                 would have tsf >= hw_tsf). Since we cannot use the 
     4496                 hardware TSF, we will do nothing and wait for the 
     4497                 next beacon. In order to do so, we set sc->syncbeacon 
     4498                 again */ 
     4499 
     4500              sc->sc_syncbeacon = 1; 
     4501              goto ath_beacon_config_debug; 
     4502 
     4503            } else { 
     4504 
     4505              /* We do receive a beacon in the past, normal case. We 
     4506                 make sure that the timestamp is at least FUDGE ms 
     4507                 ahead of the hardware TSF */ 
     4508 
     4509              nexttbtt = tsftu + intval; 
     4510              while (nexttbtt <= hw_tsftu + FUDGE) { 
     4511                nexttbtt += intval; 
     4512              } 
     4513            } 
     4514          } 
     4515        } 
     4516 
    44564517        if (ic->ic_opmode == IEEE80211_M_STA && !(sc->sc_nostabeacons)) { 
    44574518                HAL_BEACON_STATE bs; 
    4458                 u_int64_t tsf; 
    4459                 u_int32_t tsftu; 
    44604519                int dtimperiod, dtimcount; 
    44614520                int cfpperiod, cfpcount; 
    44624521 
     
    44724531                        dtimcount = 0;          /* XXX? */ 
    44734532                cfpperiod = 1;                  /* NB: no PCF support yet */ 
    44744533                cfpcount = 0; 
    4475 #define FUDGE   2 
    44764534                /* 
    44774535                 * Pull nexttbtt forward to reflect the current 
    44784536                 * TSF and calculate dtim+cfp state for the result. 
    44794537                 */ 
    4480                 tsf = ath_hal_gettsf64(ah); 
    4481                 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE; 
     4538 
     4539                /* FIXME : nexttbtt computation has been changed */ 
     4540                nexttbtt = tsftu; 
    44824541                do { 
    44834542                        nexttbtt += intval; 
    44844543                        if (--dtimcount < 0) { 
     
    44864545                                if (--cfpcount < 0) 
    44874546                                        cfpcount = cfpperiod - 1; 
    44884547                        } 
    4489                 } while (nexttbtt < tsftu); 
     4548                } while (nexttbtt < hw_tsftu + FUDGE); 
    44904549#undef FUDGE 
    44914550                memset(&bs, 0, sizeof(bs)); 
    44924551                bs.bs_intval = intval; 
     
    45384597                DPRINTF(sc, ATH_DEBUG_BEACON,  
    45394598                        "%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" 
    45404599                        , __func__ 
    4541                         , (long long) tsf, tsftu 
     4600                        , (long long) hw_tsf, hw_tsftu 
    45424601                        , bs.bs_intval 
    45434602                        , bs.bs_nexttbtt 
    45444603                        , bs.bs_dtimperiod 
     
    45574616                ath_hal_intrset(ah, sc->sc_imask); 
    45584617        } else { 
    45594618                ath_hal_intrset(ah, 0); 
    4560                 if (nexttbtt == intval
     4619                if (should_reset_tsf
    45614620                        intval |= HAL_BEACON_RESET_TSF; 
    45624621                if (ic->ic_opmode == IEEE80211_M_IBSS) { 
    45634622                        /* 
     
    45944653                if (ic->ic_opmode == IEEE80211_M_IBSS && sc->sc_hasveol) 
    45954654                        ath_beacon_start_adhoc(sc, vap); 
    45964655        } 
    4597         sc->sc_syncbeacon = 0; 
    45984656#undef TSF_TO_TU 
     4657 
     4658 ath_beacon_config_debug: 
     4659 
     4660        /* we print all debug messages here, in order to preserve the 
     4661           time critical aspect of this function */ 
     4662 
     4663        DPRINTF(sc, ATH_DEBUG_BEACON, 
     4664                "%s: ni=%p tsf=%llu hw_tsf=%llu tsftu=%u hw_tsftu=%u\n", 
     4665                __func__, ni, tsf, hw_tsf, tsftu, hw_tsftu); 
     4666 
     4667        if (should_reset_tsf) { 
     4668          /* we just created the interface */ 
     4669          DPRINTF(sc, ATH_DEBUG_BEACON, "%s: first beacon\n",__func__); 
     4670        } else { 
     4671          if (tsf == 1) { 
     4672            /* we do not receive any beacons or probe response */ 
     4673            DPRINTF(sc, ATH_DEBUG_BEACON, 
     4674                    "%s: no beacon received...\n",__func__); 
     4675          } else { 
     4676            if (tsf > hw_tsf) { 
     4677              /* we do receive a beacon and the hw TSF has not been updated */ 
     4678              DPRINTF(sc, ATH_DEBUG_BEACON, 
     4679                      "%s: beacon received, but TSF is incorrect\n",__func__); 
     4680            } else { 
     4681              /* we do receive a beacon in the past, normal case */ 
     4682              DPRINTF(sc, ATH_DEBUG_BEACON, 
     4683                      "%s: beacon received, TSF is correct\n",__func__); 
     4684            } 
     4685          } 
     4686        } 
     4687 
     4688        DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt=%u intval=%u\n", 
     4689                __func__,nexttbtt, intval & HAL_BEACON_PERIOD); 
    45994690} 
    46004691 
    46014692static int