| 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 | |
|---|
| | 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); |
|---|