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

File madwifi-ibss-merge-clean.2.diff, 11.3 kB (added by mentor, 1 year ago)

Mangled version of above

  • 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        } 
     
    11881187        struct ieee80211com *ic = vap->iv_ic; 
    11891188        struct ieee80211_node *ni; 
    11901189 
    1191         ni = ieee80211_dup_bss(vap, wh->i_addr2, 1); 
     1190        ni = ieee80211_dup_bss(vap, wh->i_addr2, 0); 
    11921191        if (ni != NULL) { 
    11931192                ni->ni_esslen = sp->ssid[1]; 
    11941193                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; 
     364                 
    363365                /* Assume each node needs 500 bytes */ 
    364366                if (buf + space < p + 500) 
    365367                        break; 
    366  
    367                 if (ni->ni_vap == vap && 
    368                     0 != memcmp(vap->iv_myaddr, ni->ni_macaddr, IEEE80211_ADDR_LEN)) { 
    369                         struct timespec t; 
     368                if ((ni->ni_vap == vap) && 
     369                    !memcmp(vap->iv_myaddr, ni->ni_macaddr, IEEE80211_ADDR_LEN)) { 
    370370                        jiffies_to_timespec(jiffies - ni->ni_last_rx, &t); 
    371                         p += sprintf(p, "macaddr: <%s>\n", ether_sprintf(ni->ni_macaddr)); 
     371                        p += sprintf(p, "ni: %p%s vap: %p macaddr: <%s>\n", 
     372                                     ni, ni == ni->ni_vap->iv_bss ? "*" : " ", 
     373                                     ni->ni_vap, ether_sprintf(ni->ni_macaddr)); 
    372374                        p += sprintf(p, " rssi %d\n", ni->ni_rssi); 
    373375 
    374376                        p += sprintf(p, " last_rx %ld.%06ld\n", 
    375377                                     t.tv_sec, t.tv_nsec / 1000); 
    376  
     378                        p += sprintf(p, " ni_tstamp %10llu ni_rtsf %10llu\n", 
     379                                     le64_to_cpu(ni->ni_tstamp.tsf), ni->ni_rtsf); 
    377380                } 
    378381        } 
    379382        IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt); 
     383 
    380384        return (p - buf); 
    381385} 
    382386 
  • ath/if_ath.c

    old new  
    44134413 * the beacon miss handling so we'll receive a BMISS 
    44144414 * interrupt when we stop seeing beacons from the AP 
    44154415 * we've associated with. 
     4416 * 
     4417 * Note : TBTT is Target Beacon Transmission Time (see IEEE  
     4418 * 802.11-1999: 4 & 11.2.1.3). 
    44164419 */ 
    44174420static void 
    44184421ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap) 
     
    44224425        struct ieee80211com *ic = &sc->sc_ic; 
    44234426        struct ath_hal *ah = sc->sc_ah; 
    44244427        struct ieee80211_node *ni; 
    4425         u_int32_t nexttbtt, intval; 
     4428        u_int32_t nexttbtt = 0; 
     4429        u_int32_t intval; 
     4430        u_int64_t tsf, hw_tsf; 
     4431        u_int32_t tsftu, hw_tsftu; 
     4432        int reset_tsf = 0; 
    44264433 
    44274434        if (vap == NULL) 
    44284435                vap = TAILQ_FIRST(&ic->ic_vaps);   /* XXX */ 
    44294436 
    44304437        ni = vap->iv_bss; 
    44314438 
    4432         /* extract tstamp from last beacon and convert to TU */ 
    4433         nexttbtt = TSF_TO_TU(LE_READ_4(ni->ni_tstamp.data + 4), 
    4434                              LE_READ_4(ni->ni_tstamp.data)); 
    4435         /* XXX conditionalize multi-bss support? */ 
     4439        hw_tsf = ath_hal_gettsf64(ah); 
     4440        tsf = le64_to_cpu(ni->ni_tstamp.tsf); 
     4441        hw_tsftu = hw_tsf >> 10; 
     4442        tsftu = tsf >> 10; 
     4443 
     4444        /* We should reset hw TSF only once, so we increment 
     4445         * ni_tstamp.tsf to avoid resetting the hw TSF multiple 
     4446         * times */ 
     4447 
     4448        if (tsf == 0) { 
     4449                reset_tsf = 1; 
     4450                ni->ni_tstamp.tsf = cpu_to_le64(1); 
     4451        } 
     4452 
     4453        /* XXX: Conditionalize multi-bss support? */ 
    44364454        if (ic->ic_opmode == IEEE80211_M_HOSTAP) { 
    4437                 /* 
    4438                  * For multi-bss ap support beacons are either staggered 
     4455                /* For multi-bss ap support beacons are either staggered 
    44394456                 * evenly over N slots or burst together.  For the former 
    44404457                 * arrange for the SWBA to be delivered for each slot. 
    4441                  * Slots that are not occupied will generate nothing.  
    4442                  */ 
     4458                 * Slots that are not occupied will generate nothing. */ 
    44434459                /* NB: the beacon interval is kept internally in TUs */ 
    44444460                intval = ic->ic_lintval & HAL_BEACON_PERIOD; 
    44454461                if (sc->sc_stagbeacons) 
    44464462                        intval /= ATH_BCBUF;    /* for staggered beacons */ 
    44474463                if ((sc->sc_nostabeacons) && 
    4448                     (vap->iv_opmode == IEEE80211_M_HOSTAP)) 
    4449                         nexttbtt = 0
     4464                       (vap->iv_opmode == IEEE80211_M_HOSTAP)) 
     4465                        reset_tsf = 1
    44504466        } else 
    44514467                intval = ni->ni_intval & HAL_BEACON_PERIOD; 
    4452         if (nexttbtt == 0)              /* e.g. for ap mode */ 
     4468 
     4469#define FUDGE   2 
     4470        sc->sc_syncbeacon = 0; 
     4471 
     4472        if (reset_tsf) { 
     4473                /* We just created the interface and TSF will be reset to 
     4474                 * zero, so next beacon will be sent at the next intval 
     4475                 * time */ 
    44534476                nexttbtt = intval; 
    4454         else if (intval)                /* NB: can be 0 for monitor mode */ 
    4455                 nexttbtt = roundup(nexttbtt, intval); 
    4456         DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt %u intval %u (%u)\n", 
    4457                 __func__, nexttbtt, intval, ni->ni_intval); 
     4477        } else if (intval) {    /* NB: can be 0 for monitor mode */ 
     4478                if (tsf == 1) { 
     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                        nexttbtt = roundup(hw_tsftu + FUDGE, intval); 
     4486                } else { 
     4487                        if (tsf > hw_tsf) { 
     4488                                /* We do receive a beacon from someone else in  
     4489                                 * the past, but the HW TSF has not been  
     4490                                 * updated (otherwise we would have tsf >=  
     4491                                 * hw_tsf). Since we cannot use the hardware  
     4492                                 * TSF, we will do nothing and wait for the next  
     4493                                 * beacon. In order to do so, we set  
     4494                                 * sc->syncbeacon again */ 
     4495                                sc->sc_syncbeacon = 1; 
     4496                                goto ath_beacon_config_debug; 
     4497                        } else { 
     4498                                /* We do receive a beacon in the past, normal case. We 
     4499                                 * make sure that the timestamp is at least FUDGE ms 
     4500                                 * ahead of the hardware TSF */ 
     4501                                nexttbtt = tsftu + intval; 
     4502                                if (nexttbtt <= (hw_tsftu + FUDGE)) 
     4503                                        nexttbtt = roundup(hw_tsftu + FUDGE, intval); 
     4504                        } 
     4505                } 
     4506        } 
     4507 
    44584508        if (ic->ic_opmode == IEEE80211_M_STA && !(sc->sc_nostabeacons)) { 
    44594509                HAL_BEACON_STATE bs; 
    4460                 u_int64_t tsf; 
    4461                 u_int32_t tsftu; 
    44624510                int dtimperiod, dtimcount; 
    44634511                int cfpperiod, cfpcount; 
    44644512 
    4465                 /* 
    4466                  * Setup dtim and cfp parameters according to 
    4467                  * last beacon we received (which may be none). 
    4468                  */ 
     4513                /* Setup DTIM and CFP parameters according to the last beacon  
     4514                 * we have received (which may not have happened). */ 
    44694515                dtimperiod = vap->iv_dtim_period; 
    44704516                if (dtimperiod <= 0)            /* NB: 0 if not known */ 
    44714517                        dtimperiod = 1; 
     
    44744520                        dtimcount = 0;          /* XXX? */ 
    44754521                cfpperiod = 1;                  /* NB: no PCF support yet */ 
    44764522                cfpcount = 0; 
    4477 #define FUDGE   2 
    44784523                /* 
    44794524                 * Pull nexttbtt forward to reflect the current 
    44804525                 * TSF and calculate dtim+cfp state for the result. 
    44814526                 */ 
    4482                 tsf = ath_hal_gettsf64(ah); 
    4483                 tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE; 
     4527                nexttbtt = tsftu; 
     4528                if (nexttbtt == 0)              /* e.g. for ap mode */ 
     4529                        nexttbtt = intval; 
    44844530                do { 
    44854531                        nexttbtt += intval; 
    44864532                        if (--dtimcount < 0) { 
     
    44884534                                if (--cfpcount < 0) 
    44894535                                        cfpcount = cfpperiod - 1; 
    44904536                        } 
    4491                 } while (nexttbtt < tsftu); 
     4537                } while (nexttbtt < hw_tsftu + FUDGE); 
    44924538#undef FUDGE 
    44934539                memset(&bs, 0, sizeof(bs)); 
    44944540                bs.bs_intval = intval; 
     
    45624608                ath_hal_intrset(ah, sc->sc_imask); 
    45634609        } else { 
    45644610                ath_hal_intrset(ah, 0); 
    4565                 if (nexttbtt == intval
     4611                if (reset_tsf
    45664612                        intval |= HAL_BEACON_RESET_TSF; 
    45674613                if (ic->ic_opmode == IEEE80211_M_IBSS) { 
    45684614                        /* 
     
    45994645                if (ic->ic_opmode == IEEE80211_M_IBSS && sc->sc_hasveol) 
    46004646                        ath_beacon_start_adhoc(sc, vap); 
    46014647        } 
    4602         sc->sc_syncbeacon = 0; 
    46034648#undef TSF_TO_TU 
     4649 
     4650        ath_beacon_config_debug: 
     4651        /* We print all debug messages here, in order to preserve the 
     4652         * time critical aspect of this function */ 
     4653        DPRINTF(sc, ATH_DEBUG_BEACON, 
     4654                "%s: ni=%p tsf=%llu hw_tsf=%llu tsftu=%u hw_tsftu=%u\n", 
     4655                __func__, ni, tsf, hw_tsf, tsftu, hw_tsftu); 
     4656 
     4657        if (reset_tsf) 
     4658                /* We just created the interface */ 
     4659                DPRINTF(sc, ATH_DEBUG_BEACON, "%s: first beacon\n", __func__); 
     4660        else if (tsf == 1) 
     4661                /* We do not receive any beacons or probe response */ 
     4662                DPRINTF(sc, ATH_DEBUG_BEACON, 
     4663                                "%s: no beacon received...\n",__func__); 
     4664        else if (tsf > hw_tsf) 
     4665                /* We do receive a beacon and the hw TSF has not been updated */ 
     4666                DPRINTF(sc, ATH_DEBUG_BEACON, 
     4667                                "%s: beacon received, but TSF is incorrect\n",  
     4668                                __func__); 
     4669        else 
     4670                /* We do receive a beacon in the past, normal case */ 
     4671                DPRINTF(sc, ATH_DEBUG_BEACON, 
     4672                                "%s: beacon received, TSF is correct\n",  
     4673                                __func__); 
     4674 
     4675        DPRINTF(sc, ATH_DEBUG_BEACON, "%s: nexttbtt=%u intval=%u\n", 
     4676                __func__, nexttbtt, intval & HAL_BEACON_PERIOD); 
    46044677} 
    46054678 
    46064679static int 
     
    54435516        struct ath_softc *sc = ni->ni_ic->ic_dev->priv; 
    54445517        struct ieee80211vap *vap = ni->ni_vap; 
    54455518 
    5446         /* 
    5447          * Call up first so subsequent work can use information 
    5448          * potentially stored in the node (e.g. for ibss merge). 
    5449          */ 
     5519        /* Call up first so subsequent work can use information 
     5520         * potentially stored in the node (e.g. for ibss merge). */ 
    54505521        sc->sc_recv_mgmt(ni, skb, subtype, rssi, rtsf); 
    54515522        switch (subtype) { 
    54525523        case IEEE80211_FC0_SUBTYPE_BEACON: 
    5453                 /* update rssi statistics for use by the HAL */ 
     5524                /* Update RSSI statistics for use by the HAL */ 
    54545525                ATH_RSSI_LPF(ATH_NODE(ni)->an_halstats.ns_avgbrssi, rssi); 
    54555526                if ((sc->sc_syncbeacon || (vap->iv_flags_ext & IEEE80211_FEXT_APPIE_UPDATE)) && 
    54565527                    ni == vap->iv_bss && vap->iv_state == IEEE80211_S_RUN) { 
    5457                         /* 
    5458                          * Resync beacon timers using the tsf of the 
    5459                          * beacon frame we just received. 
    5460                          */ 
     5528                        /* Resync beacon timers using the TSF of the 
     5529                         * beacon frame we just received. */ 
    54615530                        vap->iv_flags_ext &= ~IEEE80211_FEXT_APPIE_UPDATE; 
    54625531                        ath_beacon_config(sc, vap); 
    54635532                } 
    5464                 /* fall thru... */ 
     5533                /* NB: Fall Through */ 
    54655534        case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 
    54665535                if (vap->iv_opmode == IEEE80211_M_IBSS && 
    5467                     vap->iv_state == IEEE80211_S_RUN) { 
    5468                         /* 
    5469                          * Handle IBSS merge as needed; check the TSF on the 
     5536                                vap->iv_state == IEEE80211_S_RUN) { 
     5537                        /* Don't merge if we have a desired BSSID */ 
     5538                        if (vap->iv_flags & IEEE80211_F_DESBSSID) 
     5539                                break; 
     5540 
     5541                        /* To handle IBSS merge, we need the struct 
     5542                         * ieee80211_node which has been updated with the 
     5543                         * BSSID and TSF from the last beacon */ 
     5544                        ni = ieee80211_find_rxnode(ni->ni_ic, 
     5545                                        (const struct ieee80211_frame_min *) skb->data); 
     5546                        if (ni == NULL) 
     5547                                break; 
     5548 
     5549                        /* Handle IBSS merge as needed; check the TSF on the 
    54705550                         * frame before attempting the merge.  The 802.11 spec 
    54715551                         * says the station should change its BSSID to match 
    54725552                         * the oldest station with the same SSID, where oldest 
    54735553                         * is determined by the TSF.  Note that hardware 
    54745554                         * reconfiguration happens through callback to 
    54755555                         * ath_newstate as the state machine will go from 
    5476                          * RUN -> RUN when this happens. 
    5477                          */ 
    5478                         /* jal: added: don't merge if we have a desired 
    5479                            BSSID */ 
    5480                         if (!(vap->iv_flags & IEEE80211_F_DESBSSID) && 
    5481                                 le64_to_cpu(ni->ni_tstamp.tsf) >= rtsf) { 
    5482                                 DPRINTF(sc, ATH_DEBUG_STATE, 
    5483                                         "ibss merge, rtsf %10llu local tsf %10llu\n", 
    5484                                         rtsf, 
    5485                                         (unsigned long long) le64_to_cpu(ni->ni_tstamp.tsf)); 
    5486                                 (void) ieee80211_ibss_merge(ni); 
     5556                         * RUN -> RUN when this happens. */ 
     5557                        DPRINTF(sc, ATH_DEBUG_BEACON, 
     5558                                        "check for ibss merge for ni=%p TSF1(t4)=%10llu TSF2(t3)=%10llu\n", 
     5559                                        ni, rtsf, le64_to_cpu(ni->ni_tstamp.tsf)); 
     5560 
     5561                        if (rtsf < le64_to_cpu(ni->ni_tstamp.tsf)) { 
     5562                                DPRINTF(sc, ATH_DEBUG_BEACON, 
     5563                                                "ibss merge, rtsf %10llu local tsf %10llu\n", 
     5564                                                rtsf, le64_to_cpu(ni->ni_tstamp.tsf)); 
     5565                                ieee80211_ibss_merge(ni); 
    54875566                        } 
    54885567                } 
    54895568                break;