Ticket #1033: madwifi-ibss-merge-clean.diff

File madwifi-ibss-merge-clean.diff, 9.6 kB (added by benoit.papillault@free.fr, 1 year ago)

Updated version of adhoc-beacon-5.diff

  • net80211/ieee80211_node.c

    old new  
    517517        struct ieee80211com *ic = ni->ni_ic; 
    518518#endif 
    519519 
    520         if (ni == vap->iv_bss || 
    521             IEEE80211_ADDR_EQ(ni->ni_bssid, vap->iv_bss->ni_bssid)) { 
     520        if (ni == vap->iv_bss) { 
    522521                /* unchanged, nothing to do */ 
    523522                return 0; 
    524523        } 
     
    11951194        struct ieee80211com *ic = vap->iv_ic; 
    11961195        struct ieee80211_node *ni; 
    11971196 
    1198         ni = ieee80211_dup_bss(vap, wh->i_addr2, 1); 
     1197        ni = ieee80211_dup_bss(vap, wh->i_addr2, 0); 
    11991198        if (ni != NULL) { 
    12001199                ni->ni_esslen = sp->ssid[1]; 
    12011200                memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]); 
  • net80211/ieee80211_linux.c

    old new  
    360360 
    361361        IEEE80211_NODE_TABLE_LOCK_IRQ(nt); 
    362362        TAILQ_FOREACH(ni, &nt->nt_node, ni_list) { 
     363                        struct timespec t; 
    363364                /* Assume each node needs 500 bytes */ 
    364365                if (buf + space < p + 500) 
    365366                        break; 
    366  
     367                /* 
    367368                if (ni->ni_vap == vap && 
    368369                    0 != memcmp(vap->iv_myaddr, ni->ni_macaddr, IEEE80211_ADDR_LEN)) { 
    369                        struct timespec t; 
     370                */ 
    370371                        jiffies_to_timespec(jiffies - ni->ni_last_rx, &t); 
    371                         p += sprintf(p, "macaddr: <%s>\n", ether_sprintf(ni->ni_macaddr)); 
     372                        p += sprintf(p, "ni: %p%s vap: %p macaddr: <%s>\n", 
     373                                     ni, ni == ni->ni_vap->iv_bss ? "*" : " ", 
     374                                     ni->ni_vap, ether_sprintf(ni->ni_macaddr)); 
    372375                        p += sprintf(p, " rssi %d\n", ni->ni_rssi); 
    373376 
    374377                        p += sprintf(p, " last_rx %ld.%06ld\n", 
    375378                                     t.tv_sec, t.tv_nsec / 1000); 
    376  
     379                        p += sprintf(p, " ni_tstamp %10llu ni_rtsf %10llu\n", 
     380                                     le64_to_cpu(ni->ni_tstamp.tsf), ni->ni_rtsf); 
     381                        /* 
    377382                } 
     383                        */ 
    378384        } 
    379385        IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt); 
    380386        return (p - buf); 
  • ath/if_ath.c

    old new  
    45404540 * the beacon miss handling so we'll receive a BMISS 
    45414541 * interrupt when we stop seeing beacons from the AP 
    45424542 * we've associated with. 
     4543 * 
     4544 * Note : TBTT is Target Beacon Transmission Time (see IEEE 802.11-1999) 
    45434545 */ 
    45444546static void 
    45454547ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap) 
     
    45494551        struct ieee80211com *ic = &sc->sc_ic; 
    45504552        struct ath_hal *ah = sc->sc_ah; 
    45514553        struct ieee80211_node *ni; 
    4552         u_int32_t nexttbtt, intval; 
     4554        u_int32_t nexttbtt = 0; 
     4555        u_int32_t intval; 
     4556        u_int64_t tsf, hw_tsf; 
     4557        u_int32_t tsftu, hw_tsftu; 
     4558        int should_reset_tsf = 0; 
    45534559 
    45544560        if (vap == NULL) 
    45554561                vap = TAILQ_FIRST(&ic->ic_vaps);   /* XXX */ 
    45564562 
    45574563        ni = vap->iv_bss; 
    45584564 
    4559         /* extract tstamp from last beacon and convert to TU */ 
    4560         nexttbtt = TSF_TO_TU(LE_READ_4(ni->ni_tstamp.data + 4), 
    4561                              LE_READ_4(ni->ni_tstamp.data)); 
     4565        hw_tsf = ath_hal_gettsf64(ah); 
     4566        tsf = le64_to_cpu(ni->ni_tstamp.tsf); 
     4567        hw_tsftu = hw_tsf >> 10; 
     4568        tsftu = tsf >> 10; 
     4569 
     4570        /* we should reset hw TSF only once, so we increment 
     4571           ni_tstamp.tsf to avoid resetting the hw TSF multiple 
     4572           times */ 
     4573 
     4574        if (tsf == 0) { 
     4575                should_reset_tsf = 1; 
     4576                ni->ni_tstamp.tsf = cpu_to_le64(1); 
     4577        } 
     4578 
    45624579        /* XXX conditionalize multi-bss support? */ 
    45634580        if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 
    45644581                /* 
     
    45724589                if (sc->sc_stagbeacons) 
    45734590                        intval /= ATH_BCBUF;    /* for staggered beacons */ 
    45744591                if ((sc->sc_nostabeacons) && 
    4575                     (vap->iv_opmode == IEEE80211_M_HOSTAP)) 
    4576                         nexttbtt = 0
     4592                       (vap->iv_opmode == IEEE80211_M_HOSTAP)) 
     4593                        should_reset_tsf = 1
    45774594        } else 
    45784595                intval = ni->ni_intval & HAL_BEACON_PERIOD; 
    4579         if (nexttbtt == 0)              /* e.g. for ap mode */ 
     4596 
     4597#define FUDGE   2 
     4598        sc->sc_syncbeacon = 0; 
     4599 
     4600        if (should_reset_tsf) { 
     4601 
     4602                /* We just created the interface and TSF will be reset to 
     4603                   zero, so next beacon will be sent at the next intval 
     4604                   time */ 
     4605 
    45804606                nexttbtt = intval; 
    4581         else if (intval)                /* NB: can be 0 for monitor mode */ 
    4582                 nexttbtt = roundup(nexttbtt, intval); 
    4583         DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt %u intval %u (%u)\n", 
    4584                 __func__, nexttbtt, intval, ni->ni_intval); 
     4607        } else if (intval) {    /* NB: can be 0 for monitor mode */ 
     4608                if (tsf == 1) { 
     4609         
     4610                        /* We do not receive any beacons or probe response. Since 
     4611                           a beacon should be sent every 'intval' ms, we compute 
     4612                           the next beacon timestamp using the hardware TSF. We 
     4613                           ensure that it is at least FUDGE ms ahead of the 
     4614                           current TSF. Otherwise, we use the next beacon 
     4615                           timestamp again */ 
     4616 
     4617                        nexttbtt = roundup(hw_tsftu +1, intval); 
     4618                        while (nexttbtt <= hw_tsftu + FUDGE) { 
     4619                                nexttbtt += intval; 
     4620                        } 
     4621                } else { 
     4622                        if (tsf > hw_tsf) { 
     4623 
     4624                        /* We do receive a beacon from someone else in the past, 
     4625                           but the hw TSF has not been updated (otherwise we 
     4626                           would have tsf >= hw_tsf). Since we cannot use the 
     4627                           hardware TSF, we will do nothing and wait for the 
     4628                           next beacon. In order to do so, we set sc->syncbeacon 
     4629                           again */ 
     4630 
     4631                                sc->sc_syncbeacon = 1; 
     4632                                goto ath_beacon_config_debug; 
     4633                        } else { 
     4634                                /* We do receive a beacon in the past, normal case. We 
     4635                                   make sure that the timestamp is at least FUDGE ms 
     4636                                   ahead of the hardware TSF */ 
     4637 
     4638                                nexttbtt = tsftu + intval; 
     4639                                while (nexttbtt <= hw_tsftu + FUDGE) { 
     4640                                        nexttbtt += intval; 
     4641                                } 
     4642                        } 
     4643                } 
     4644        } 
     4645 
    45854646        if (ic->ic_opmode == IEEE80211_M_STA && !(sc->sc_nostabeacons)) { 
    45864647                HAL_BEACON_STATE bs; 
    4587                 u_int64_t tsf; 
    4588                 u_int32_t tsftu; 
    45894648                int dtimperiod, dtimcount; 
    45904649                int cfpperiod, cfpcount; 
    45914650 
     
    46014660                        dtimcount = 0;          /* XXX? */ 
    46024661                cfpperiod = 1;                  /* NB: no PCF support yet */ 
    46034662                cfpcount = 0; 
    4604 #define FUDGE   2 
    46054663                /* 
    46064664                 * Pull nexttbtt forward to reflect the current 
    46074665                 * TSF and calculate dtim+cfp state for the result. 
    46084666                 */ 
    4609                 tsf = ath_hal_gettsf64(ah); 
    4610                 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE; 
     4667                nexttbtt = tsftu; 
     4668                if (nexttbtt == 0)              /* e.g. for ap mode */ 
     4669                        nexttbtt = intval; 
    46114670                do { 
    46124671                        nexttbtt += intval; 
    46134672                        if (--dtimcount < 0) { 
     
    46154674                                if (--cfpcount < 0) 
    46164675                                        cfpcount = cfpperiod - 1; 
    46174676                        } 
    4618                 } while (nexttbtt < tsftu); 
     4677                } while (nexttbtt < hw_tsftu + FUDGE); 
    46194678#undef FUDGE 
    46204679                memset(&bs, 0, sizeof(bs)); 
    46214680                bs.bs_intval = intval; 
     
    46894748                ath_hal_intrset(ah, sc->sc_imask); 
    46904749        } else { 
    46914750                ath_hal_intrset(ah, 0); 
    4692                 if (nexttbtt == intval
     4751                if (should_reset_tsf
    46934752                        intval |= HAL_BEACON_RESET_TSF; 
    46944753                if (ic->ic_opmode == IEEE80211_M_IBSS) { 
    46954754                        /* 
     
    47264785                if (ic->ic_opmode == IEEE80211_M_IBSS && sc->sc_hasveol) 
    47274786                        ath_beacon_start_adhoc(sc, vap); 
    47284787        } 
    4729         sc->sc_syncbeacon = 0; 
    47304788#undef TSF_TO_TU 
     4789 
     4790        ath_beacon_config_debug: 
     4791 
     4792        /* we print all debug messages here, in order to preserve the 
     4793           time critical aspect of this function */ 
     4794 
     4795        DPRINTF(sc, ATH_DEBUG_BEACON, 
     4796                "%s: ni=%p tsf=%llu hw_tsf=%llu tsftu=%u hw_tsftu=%u\n", 
     4797                __func__, ni, tsf, hw_tsf, tsftu, hw_tsftu); 
     4798 
     4799        if (should_reset_tsf) { 
     4800                /* we just created the interface */ 
     4801                DPRINTF(sc, ATH_DEBUG_BEACON, "%s: first beacon\n",__func__); 
     4802        } else { 
     4803                if (tsf == 1) { 
     4804                        /* we do not receive any beacons or probe response */ 
     4805                        DPRINTF(sc, ATH_DEBUG_BEACON, 
     4806                                "%s: no beacon received...\n",__func__); 
     4807                } else { 
     4808                        if (tsf > hw_tsf) { 
     4809                                /* we do receive a beacon and the hw TSF has not been updated */ 
     4810                                DPRINTF(sc, ATH_DEBUG_BEACON, 
     4811                                        "%s: beacon received, but TSF is incorrect\n",__func__); 
     4812                        } else { 
     4813                                /* we do receive a beacon in the past, normal case */ 
     4814                                DPRINTF(sc, ATH_DEBUG_BEACON, 
     4815                                        "%s: beacon received, TSF is correct\n",__func__); 
     4816                        } 
     4817                } 
     4818        } 
     4819 
     4820        DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt=%u intval=%u\n", 
     4821                __func__,nexttbtt, intval & HAL_BEACON_PERIOD); 
    47314822} 
    47324823 
    47334824static int 
     
    55955686        case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 
    55965687                if (vap->iv_opmode == IEEE80211_M_IBSS && 
    55975688                    vap->iv_state == IEEE80211_S_RUN) { 
     5689                   
     5690                  /* jal: added: don't merge if we have a desired 
     5691                     BSSID */ 
     5692 
     5693                  if (vap->iv_flags & IEEE80211_F_DESBSSID) { 
     5694                    break; 
     5695                  } 
     5696 
     5697                  /* To handle IBSS merge, we need the struct 
     5698                     ieee80211_node which has been updated with the 
     5699                     BSSID and TSF from the last beacon */ 
     5700 
     5701                  ni = ieee80211_find_rxnode(ni->ni_ic, 
     5702                                             (const struct ieee80211_frame_min *) skb->data); 
     5703                  if (ni == NULL) { 
     5704                    break; 
     5705                  } 
     5706 
    55985707                        /* 
    55995708                         * Handle IBSS merge as needed; check the TSF on the 
    56005709                         * frame before attempting the merge.  The 802.11 spec 
     
    56055714                         * ath_newstate as the state machine will go from 
    56065715                         * RUN -> RUN when this happens. 
    56075716                         */ 
    5608                         /* jal: added: don't merge if we have a desired 
    5609                            BSSID */ 
    5610                         if (!(vap->iv_flags & IEEE80211_F_DESBSSID) && 
    5611                                 le64_to_cpu(ni->ni_tstamp.tsf) >= rtsf) { 
    5612                                 DPRINTF(sc, ATH_DEBUG_STATE, 
    5613                                         "ibss merge, rtsf %10llu local tsf %10llu\n", 
    5614                                         rtsf, 
    5615                                         (unsigned long long) le64_to_cpu(ni->ni_tstamp.tsf)); 
    5616                                 (void) ieee80211_ibss_merge(ni); 
    5617                         } 
     5717 
     5718                  DPRINTF(sc, ATH_DEBUG_BEACON, 
     5719                          "check for ibss merge for ni=%p TSF1(t4)=%10llu TSF2(t3)=%10llu\n", 
     5720                          ni, rtsf, le64_to_cpu(ni->ni_tstamp.tsf)); 
     5721 
     5722                  if (rtsf < le64_to_cpu(ni->ni_tstamp.tsf)) { 
     5723                    DPRINTF(sc, ATH_DEBUG_BEACON, 
     5724                            "ibss merge, rtsf %10llu local tsf %10llu\n", 
     5725                            rtsf, le64_to_cpu(ni->ni_tstamp.tsf)); 
     5726                    ieee80211_ibss_merge(ni); 
     5727                  } 
    56185728                } 
    56195729                break; 
    56205730        }