/// Called when MLME receives a beacon or probe response so that scanner saves it in a BSS map.
///
/// This method is a no-op if no scan request is in progress.
Called when MLME receives a beacon or probe response so that scanner saves it in a BSS map.
This method is a no-op if no scan request is in progress.
Called when MLME receives a beacon or probe response so that scanner saves it in a BSS map . This method is a no - op if no scan request is in progress .
pub fn handle_beacon_or_probe_response(
        &mut self,
        bssid: Bssid,
        timestamp: u64,
        beacon_interval: TimeUnit,
        capability_info: CapabilityInfo,
        ies: &[u8],
        rx_info: Option<banjo_wlan_mac::WlanRxInfo>,
    ) {
        let seen_bss = match &mut self.scanner.ongoing_scan {
            Some(req) => &mut req.seen_bss,
            None => return,
        };
        match seen_bss.entry(bssid) {
            hash_map::Entry::Occupied(mut entry) => {
                let (existing_hash, bss_description) = entry.get_mut();
                if timestamp < bss_description.timestamp {
                    return;
                }
                let hash = beacon_hash(beacon_interval, capability_info, ies);
                if hash != *existing_hash {
                    let new_bss_description = construct_bss_description(
                        bssid,
                        timestamp,
                        beacon_interval,
                        capability_info,
                        ies,
                        rx_info,
                    );
                    let mut new_bss_description = match new_bss_description {
                        Ok(bss) => bss,
                        Err(e) => {
                            warn!("Failed to parse beacon or probe response: {}", e);
                            return;
                        }
                    };
                    // In case where AP is hidden, its SSID is blank (all 0) in beacon but contains
                    // the actual SSID in probe response. So if we receive a blank SSID, always
                    // prefer the existing one since we may have set the actual SSID if we had
                    // received a probe response previously.
                    if new_bss_description.ssid.iter().all(|b| *b == 0)
                        && bss_description.ssid.iter().any(|b| *b != 0)
                    {
                        new_bss_description.ssid = bss_description.ssid.clone();
                    }
                    // TIM element is present in beacon frame but not probe response. In case we
                    // see no DTIM period in latest frame, use value from previous one.
                    if new_bss_description.dtim_period == 0 {
                        new_bss_description.dtim_period = bss_description.dtim_period;
                    }
                    // If there's no RX info, keep old values
                    if rx_info.is_none() {
                        new_bss_description.rssi_dbm = bss_description.rssi_dbm;
                        new_bss_description.rcpi_dbmh = bss_description.rcpi_dbmh;
                        new_bss_description.rsni_dbh = bss_description.rsni_dbh;
                    }
                    *bss_description = new_bss_description;
                    *existing_hash = hash;
                }
            }
            hash_map::Entry::Vacant(entry) => {
                let hash = beacon_hash(beacon_interval, capability_info, ies);
                let bss_description = construct_bss_description(
                    bssid,
                    timestamp,
                    beacon_interval,
                    capability_info,
                    ies,
                    rx_info,
                );
                let bss_description = match bss_description {
                    Ok(bss) => bss,
                    Err(e) => {
                        warn!("Failed to parse beacon or probe response: {}", e);
                        return;
                    }
                };
                entry.insert((hash, bss_description));
            }
        }
    }
pub fn handle_beacon_or_probe_response ( & mut self , bssid : Bssid , timestamp : u64 , beacon_interval : TimeUnit , capability_info : CapabilityInfo , ies : & [ u8 ] , rx_info : Option < banjo_wlan_mac :: WlanRxInfo > , ) { let seen_bss = match & mut self . scanner . ongoing_scan { Some ( req ) => & mut req . seen_bss , None => return , } ; match seen_bss . entry ( bssid ) { hash_map :: Entry :: Occupied ( mut entry ) => { let ( existing_hash , bss_description ) = entry . get_mut ( ) ; if timestamp < bss_description . timestamp { return ; } let hash = beacon_hash ( beacon_interval , capability_info , ies ) ; if hash != * existing_hash { let new_bss_description = construct_bss_description ( bssid , timestamp , beacon_interval , capability_info , ies , rx_info , ) ; let mut new_bss_description = match new_bss_description { Ok ( bss ) => bss , Err ( e ) => { warn ! ( " " e ) ; return ; } } ; // In case where AP is hidden, its SSID is blank (all 0) in beacon but contains // the actual SSID in probe response. So if we receive a blank SSID, always // prefer the existing one since we may have set the actual SSID if we had // received a probe response previously. if new_bss_description . ssid . iter ( ) . all ( | b | * b == 0 ) && bss_description . ssid . iter ( ) . any ( | b | * b != 0 ) { new_bss_description . ssid = bss_description . ssid . clone ( ) ; } // TIM element is present in beacon frame but not probe response. In case we // see no DTIM period in latest frame, use value from previous one. if new_bss_description . dtim_period == 0 { new_bss_description . dtim_period = bss_description . dtim_period ; } // If there's no RX info, keep old values if rx_info . is_none ( ) { new_bss_description . rssi_dbm = bss_description . rssi_dbm ; new_bss_description . rcpi_dbmh = bss_description . rcpi_dbmh ; new_bss_description . rsni_dbh = bss_description . rsni_dbh ; } * bss_description = new_bss_description ; * existing_hash = hash ; } } hash_map :: Entry :: Vacant ( entry ) => { let hash = beacon_hash ( beacon_interval , capability_info , ies ) ; let bss_description = construct_bss_description ( bssid , timestamp , beacon_interval , capability_info , ies , rx_info , ) ; let bss_description = match bss_description { Ok ( bss ) => bss , Err ( e ) => { warn ! ( " " e ) ; return ; } } ; entry . insert ( ( hash , bss_description ) ) ; } } }
Called when MLME receives a beacon or probe response so that scanner saves it in a BSS map.
Called when MLME receives a beacon or probe response so that scanner saves it in a BSS map .
&mut self
bssid
Bssid
timestamp
u64
beacon_interval
TimeUnit
capability_info
CapabilityInfo
ies
&[u8]
rx_info
Option<banjo_wlan_mac::WlanRxInfo>