Ticket #1033: adhoc-beacon-3.diff

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

proper ibss nexttbtt computation

  • ath/if_ath.c

    old new  
    44244424        struct ath_hal *ah = sc->sc_ah; 
    44254425        struct ieee80211_node *ni; 
    44264426        u_int32_t nexttbtt, intval; 
     4427        u_int64_t tsf, hw_tsf; 
     4428        u_int32_t tsftu, hw_tsftu; 
     4429        int should_reset_tsf = 0; 
    44274430 
    44284431        if (vap == NULL) 
    44294432                vap = TAILQ_FIRST(&ic->ic_vaps);   /* XXX */ 
    44304433 
    44314434        ni = vap->iv_bss; 
    44324435 
    4433         /* extract tstamp from last beacon and convert to TU */ 
    4434         nexttbtt = TSF_TO_TU(LE_READ_4(ni->ni_tstamp.data + 4), 
    4435                              LE_READ_4(ni->ni_tstamp.data)); 
     4436        hw_tsf = ath_hal_gettsf64(ah); 
     4437        tsf = le64_to_cpu(ni->ni_tstamp.tsf); 
     4438        hw_tsftu = hw_tsf >> 10; 
     4439        tsftu = tsf >> 10; 
     4440        if (tsf == 0) { 
     4441          should_reset_tsf = 1; 
     4442          ni->ni_tstamp.tsf = cpu_to_le64(tsf+1); 
     4443        } 
     4444 
    44364445        /* XXX conditionalize multi-bss support? */ 
    44374446        if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 
    44384447                /* 
     
    44504459                        nexttbtt = 0; 
    44514460        } else 
    44524461                intval = ni->ni_intval & HAL_BEACON_PERIOD; 
    4453         if (nexttbtt == 0)              /* e.g. for ap mode */ 
    4454                 nexttbtt = intval; 
    4455         else if (intval)                /* NB: can be 0 for monitor mode */ 
    4456                 nexttbtt = roundup(nexttbtt, intval); 
     4462 
     4463#define FUDGE   2 
     4464        if (should_reset_tsf) { 
     4465          /* We just created the interface and TSF will be reset to 
     4466             zero, so next beacon will be sent at the next intval 
     4467             time */ 
     4468          nexttbtt = intval; 
     4469        } else { 
     4470          if (tsf == 1) { 
     4471            /* We do not receive any beacons or probe response. Since 
     4472               a beacon should be sent every 'intval' ms, we compute 
     4473               the next beacon timestamp using the hardware TSF. We 
     4474               ensure that it is at least FUDGE ms ahead of the 
     4475               current TSF. Otherwise, we use the next beacon 
     4476               timestamp again */ 
     4477            nexttbtt = roundup(hw_tsftu +1, intval); 
     4478            while (nexttbtt <= hw_tsftu + FUDGE) { 
     4479              nexttbtt += intval; 
     4480            } 
     4481          } else { 
     4482            if (tsf > hw_tsf) { 
     4483              /* We do receive a beacon from someone else in the past, 
     4484                 but the hw TSF has not been updated. Since we cannot 
     4485                 use the hardware TSF, we assume that the beacon 
     4486                 received was received less than intval ms. We add 
     4487                 another intval since we assume it is needed to let 
     4488                 the hardware TSF be updated. If we are not close to 
     4489                 the STA we received the beacon from, it might not be 
     4490                 enought */ 
     4491              nexttbtt = tsftu + intval + intval; 
     4492            } else { 
     4493              /* We do receive a beacon in the past, normal case. We 
     4494                 make sure that the timestamp is at least FUDGE ms 
     4495                 ahead of the hardware TSF */ 
     4496              nexttbtt = tsftu + intval; 
     4497              while (nexttbtt <= hw_tsftu + FUDGE) { 
     4498                nexttbtt += intval; 
     4499              } 
     4500            } 
     4501          } 
     4502        } 
     4503 
    44574504        DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt %u intval %u (%u)\n", 
    44584505                __func__, nexttbtt, intval, ni->ni_intval); 
    44594506        if (ic->ic_opmode == IEEE80211_M_STA && !(sc->sc_nostabeacons)) { 
     
    44754522                        dtimcount = 0;          /* XXX? */ 
    44764523                cfpperiod = 1;                  /* NB: no PCF support yet */ 
    44774524                cfpcount = 0; 
    4478 #define FUDGE   2 
    44794525                /* 
    44804526                 * Pull nexttbtt forward to reflect the current 
    44814527                 * TSF and calculate dtim+cfp state for the result. 
     
    45604606                ath_hal_intrset(ah, sc->sc_imask); 
    45614607        } else { 
    45624608                ath_hal_intrset(ah, 0); 
    4563                 if (nexttbtt == intval
     4609                if (should_reset_tsf
    45644610                        intval |= HAL_BEACON_RESET_TSF; 
    45654611                if (ic->ic_opmode == IEEE80211_M_IBSS) { 
    45664612                        /* 
     
    45994645        } 
    46004646        sc->sc_syncbeacon = 0; 
    46014647#undef TSF_TO_TU 
     4648 
     4649        /* we print all debug messages here, in order to preserve the 
     4650           time critical aspect of this function */ 
     4651 
     4652        printk("%s: ni=%p tsf=%lld hw_tsf=%lld tsftu=%u hw_tsftu=%u\n", 
     4653               __func__, ni, tsf, hw_tsf, tsftu, hw_tsftu); 
     4654 
     4655        if (should_reset_tsf) { 
     4656          /* we just created the interface */ 
     4657          printk("%s: first beacon\n",__func__); 
     4658        } else { 
     4659          if (tsf == 1) { 
     4660            /* we do not receive any beacons or probe response */ 
     4661            printk("%s: no beacon received...\n",__func__); 
     4662          } else { 
     4663            if (tsf > hw_tsf) { 
     4664              /* we do receive a beacon and the hw TSF has not been updated */ 
     4665              printk("%s: beacon received, but TSF is incorrect\n",__func__); 
     4666            } else { 
     4667              /* we do receive a beacon in the past, normal case */ 
     4668              printk("%s: beacon received, TSF is correct\n",__func__); 
     4669            } 
     4670          } 
     4671        } 
     4672 
     4673        printk("%s: nexttbtt=%d\n",__func__,nexttbtt); 
    46024674} 
    46034675 
    46044676static int 
  • Makefile

    old new  
    9393        for i in $(DIRS_MODULES); do \ 
    9494                $(MAKE) -C $$i install || exit 1; \ 
    9595        done 
     96        mkdir -p $(DESTDIR)/etc/modutils $(DESTDIR)/etc/modprobe.d 
     97        cp conf/ath_pci $(DESTDIR)/etc/modutils # For 2.4 kernels 
     98        cp conf/ath_pci $(DESTDIR)/etc/modprobe.d # For 2.6 kernels 
    9699ifeq ($(DESTDIR),) 
    97100        (export KMODPATH=$(KMODPATH); /sbin/depmod -ae) 
    98101endif