wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/src/core_scan_list.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of core_scan_list_c class.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 14 %
       
    20 */
       
    21 
       
    22 #include "core_scan_list.h"
       
    23 #include "core_tools.h"
       
    24 #include "core_am_tools.h"
       
    25 #include "am_debug.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 core_scan_list_c::core_scan_list_c() :
       
    33     scan_list_m( )
       
    34     {
       
    35     DEBUG( "core_scan_list_c::core_scan_list_c()" );
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 core_scan_list_c::~core_scan_list_c()
       
    42     {
       
    43     DEBUG( "core_scan_list_c::~core_scan_list_c()" );
       
    44 
       
    45     for ( core_scan_list_entry_s* iter = scan_list_m.first(); iter; iter = scan_list_m.next() )
       
    46         {
       
    47         delete iter->ap_data;
       
    48         }
       
    49 
       
    50     scan_list_m.clear();
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 u32_t core_scan_list_c::count() const
       
    57     {
       
    58     return scan_list_m.count();
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 core_error_e core_scan_list_c::update_entry(
       
    65     core_ap_data_c& ap_data )
       
    66     {
       
    67     bool_t is_match_found( false_t );
       
    68     const core_mac_address_s bssid(
       
    69         ap_data.bssid() );
       
    70     core_ssid_s ssid(
       
    71         ap_data.ssid() );    
       
    72     u64_t timestamp(
       
    73         core_am_tools_c::timestamp() );
       
    74 
       
    75     DEBUG6( "core_scan_list_c::update_entry() - searching for entries with BSSID %02X:%02X:%02X:%02X:%02X:%02X",
       
    76         bssid.addr[0], bssid.addr[1], bssid.addr[2],
       
    77         bssid.addr[3], bssid.addr[4], bssid.addr[5] );                
       
    78     DEBUG1S( "core_scan_list_c::update_entry() - and with SSID ",
       
    79         ssid.length, &ssid.ssid[0] );
       
    80 
       
    81     core_scan_list_entry_s* iter = scan_list_m.first();
       
    82     while( iter )
       
    83         {
       
    84         bool_t is_goto_next_entry( true_t );
       
    85 
       
    86         if ( iter->ap_data->bssid() == bssid )
       
    87             {
       
    88             if ( iter->ap_data->ssid() == ssid )
       
    89                 {
       
    90                 if ( !is_match_found )
       
    91                     {
       
    92                     if ( !iter->tags && iter->ap_data->rcpi() >= ap_data.rcpi() )
       
    93                         {                      
       
    94                         if ( ap_data.frame()->type() == core_frame_dot11_c::core_dot11_type_beacon )
       
    95                             {
       
    96                             DEBUG2( "core_scan_list_c::update_entry() - an entry with matching BSSID and SSID (age %u, RCPI %u) already received, ignoring beacon entry",
       
    97                                 static_cast<u32_t>( timestamp - iter->timestamp ) / SECONDS_FROM_MICROSECONDS, iter->ap_data->rcpi() );
       
    98                             }
       
    99                         else
       
   100                             {
       
   101                             DEBUG2( "core_scan_list_c::update_entry() - an entry with matching BSSID and SSID (age %u, RCPI %u) already received, ignoring probe entry",
       
   102                                 static_cast<u32_t>( timestamp - iter->timestamp ) / SECONDS_FROM_MICROSECONDS, iter->ap_data->rcpi() );
       
   103                             }
       
   104 
       
   105                         is_match_found = true_t;
       
   106                         }
       
   107                     else
       
   108                         {
       
   109                         if ( ap_data.frame()->type() == core_frame_dot11_c::core_dot11_type_beacon )
       
   110                             {
       
   111                             DEBUG2( "core_scan_list_c::update_entry() - an entry with matching BSSID and SSID (age %u, RCPI %u) found, replacing entry with a beacon entry",
       
   112                                 static_cast<u32_t>( timestamp - iter->timestamp ) / SECONDS_FROM_MICROSECONDS, iter->ap_data->rcpi() );
       
   113                             }
       
   114                         else
       
   115                             {
       
   116                             DEBUG2( "core_scan_list_c::update_entry() - an entry with matching BSSID and SSID (age %u, RCPI %u) found, replacing entry with a probe entry",
       
   117                                 static_cast<u32_t>( timestamp - iter->timestamp ) / SECONDS_FROM_MICROSECONDS, iter->ap_data->rcpi() );
       
   118                             }
       
   119 
       
   120                         is_match_found = true_t;
       
   121 
       
   122                         *(iter->ap_data) = ap_data;
       
   123                         iter->timestamp = timestamp;
       
   124                         iter->tags = 0;
       
   125                         }
       
   126                     }
       
   127                 else
       
   128                     {
       
   129                     DEBUG( "core_scan_list_c::update_entry() - an entry with matching BSSID and SSID found (duplicate), removing entry" );
       
   130 
       
   131                     core_scan_list_entry_s* temp = iter;
       
   132                     iter = scan_list_m.next();
       
   133                     scan_list_m.remove( temp );
       
   134 
       
   135                     is_goto_next_entry = false_t;
       
   136                     }
       
   137                 }
       
   138             else if ( iter->ap_data->frame()->type() == core_frame_dot11_c::core_dot11_type_beacon &&
       
   139                       ap_data.frame()->type() == core_frame_dot11_c::core_dot11_type_beacon )
       
   140                 {
       
   141                 /**
       
   142                  * If both the new entry and the old entry are beacons with different SSIDs,
       
   143                  * it means the SSID has changed and the old entry needs to be replaced or
       
   144                  * removed.
       
   145                  */
       
   146                 if ( !is_match_found )
       
   147                     {
       
   148                     DEBUG( "core_scan_list_c::update_entry() - two beacons with the same BSSID but different SSID found, replacing entry" );
       
   149                     is_match_found = true_t;
       
   150 
       
   151                     *(iter->ap_data) = ap_data;
       
   152                     iter->timestamp = timestamp;
       
   153                     iter->tags = 0;
       
   154                     }
       
   155                 else
       
   156                     {
       
   157                     DEBUG( "core_scan_list_c::update_entry() - two beacons with the same BSSID but different SSID found (duplicate), removing entry" );
       
   158 
       
   159                     core_scan_list_entry_s* temp = iter;
       
   160                     iter = scan_list_m.next();
       
   161                     scan_list_m.remove( temp );
       
   162 
       
   163                     is_goto_next_entry = false_t;
       
   164                     }
       
   165                 }
       
   166 #if 0                
       
   167             else
       
   168                 {            
       
   169                 DEBUG( "core_scan_list_c::update_entry() - an entry with matching BSSID found but SSID doesn't match, refreshing entry timestamp" );
       
   170                 iter->timestamp = timestamp;
       
   171                 }
       
   172 #endif // 0                
       
   173             }
       
   174 
       
   175         if ( is_goto_next_entry )
       
   176             {
       
   177             iter = scan_list_m.next();
       
   178             }
       
   179         }
       
   180 
       
   181     if ( !is_match_found )
       
   182         {
       
   183         if ( ap_data.frame()->type() == core_frame_dot11_c::core_dot11_type_beacon )
       
   184             {
       
   185             DEBUG( "core_scan_list_c::update_entry() - no entry matching BSSID and SSID found, adding a new beacon entry" );
       
   186             }
       
   187         else
       
   188             {
       
   189             DEBUG( "core_scan_list_c::update_entry() - no entry matching BSSID and SSID found, adding a new probe entry" );
       
   190             }
       
   191 
       
   192         core_scan_list_entry_s* entry = new core_scan_list_entry_s;
       
   193         if ( entry )
       
   194             {
       
   195             entry->ap_data = core_ap_data_c::instance( ap_data );
       
   196             entry->timestamp = timestamp;
       
   197             entry->tags = 0;
       
   198 
       
   199             scan_list_m.append( entry );
       
   200             }
       
   201         }
       
   202 
       
   203     return core_error_ok;         
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void core_scan_list_c::remove_entries_by_bssid(
       
   210     const core_mac_address_s& bssid )
       
   211     {
       
   212     DEBUG6( "core_scan_list_c::remove_entries_by_bssid() - removing entries with BSSID %02X:%02X:%02X:%02X:%02X:%02X",
       
   213         bssid.addr[0], bssid.addr[1], bssid.addr[2],
       
   214         bssid.addr[3], bssid.addr[4], bssid.addr[5] );                
       
   215 
       
   216     core_type_list_iterator_c<core_scan_list_entry_s> iter( scan_list_m );
       
   217     for( core_scan_list_entry_s* current = iter.first(); current; current = iter.next() )
       
   218         {
       
   219         if ( current->ap_data->bssid() == bssid )
       
   220             {
       
   221             DEBUG( "core_scan_list_c::remove_entries_by_bssid() - matching entry found" );
       
   222             
       
   223             iter.remove();
       
   224             
       
   225             delete current->ap_data;
       
   226             delete current;
       
   227             current = NULL;
       
   228             }
       
   229         }
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void core_scan_list_c::remove_entries_by_age(
       
   236     u32_t age )
       
   237     {
       
   238     DEBUG1( "core_scan_list_c::remove_entries_by_age() - removing entries older than %u microsecond(s)",
       
   239         age );
       
   240 
       
   241     u64_t timestamp(
       
   242         core_am_tools_c::timestamp() );
       
   243 
       
   244     core_type_list_iterator_c<core_scan_list_entry_s> iter( scan_list_m );
       
   245     for( core_scan_list_entry_s* current = iter.first(); current; current = iter.next() )
       
   246         {
       
   247         if ( static_cast<u32_t>( timestamp - current->timestamp ) > age )
       
   248             {
       
   249 #ifdef _DEBUG
       
   250             core_mac_address_s bssid(
       
   251                 current->ap_data->bssid() );
       
   252 
       
   253             DEBUG7( "core_scan_list_c::remove_entries_by_age() - BSSID %02X:%02X:%02X:%02X:%02X:%02X [%u second(s)] removed",
       
   254                 bssid.addr[0], bssid.addr[1], bssid.addr[2],
       
   255                 bssid.addr[3], bssid.addr[4], bssid.addr[5],
       
   256                 static_cast<u32_t>( timestamp - current->timestamp ) / SECONDS_FROM_MICROSECONDS );
       
   257 #endif // _DEBUG
       
   258 
       
   259             iter.remove();
       
   260 
       
   261             delete current->ap_data;
       
   262             delete current;
       
   263             current = NULL;
       
   264             }
       
   265         }
       
   266     }
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void core_scan_list_c::set_tag(
       
   272     u8_t tag )
       
   273     {
       
   274     for( core_scan_list_entry_s* iter = scan_list_m.first(); iter; iter = scan_list_m.next() )
       
   275         {
       
   276         iter->tags |= tag;
       
   277         }    
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // ---------------------------------------------------------------------------
       
   282 //       
       
   283 void core_scan_list_c::clear_tag(
       
   284     u8_t tag )
       
   285     {
       
   286     for( core_scan_list_entry_s* iter = scan_list_m.first(); iter; iter = scan_list_m.next() )
       
   287         {
       
   288         iter->tags &= ~tag;
       
   289         }    
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // ---------------------------------------------------------------------------
       
   294 //               
       
   295 void core_scan_list_c::clear_all_tags()
       
   296     {
       
   297     for( core_scan_list_entry_s* iter = scan_list_m.first(); iter; iter = scan_list_m.next() )
       
   298         {
       
   299         iter->tags = 0;
       
   300         }
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 void core_scan_list_c::print_contents()
       
   307     {
       
   308     u32_t size( sizeof( *this ) );
       
   309     u64_t timestamp = core_am_tools_c::timestamp();
       
   310 
       
   311     for( core_scan_list_entry_s* iter = scan_list_m.first(); iter; iter = scan_list_m.next() )
       
   312         {
       
   313         const core_mac_address_s bssid(
       
   314             iter->ap_data->bssid() );
       
   315         core_ssid_s ssid(
       
   316             iter->ap_data->ssid() );    
       
   317 
       
   318         DEBUG6( "core_scan_list_c::print_contents() - BSSID %02X:%02X:%02X:%02X:%02X:%02X",
       
   319             bssid.addr[0], bssid.addr[1], bssid.addr[2],
       
   320             bssid.addr[3], bssid.addr[4], bssid.addr[5] );                
       
   321         DEBUG1S( "core_scan_list_c::print_contents() - SSID ",
       
   322             ssid.length, &ssid.ssid[0] );
       
   323         DEBUG1( "core_scan_list_c::print_contents() - age %u second(s)",
       
   324             static_cast<u32_t>( timestamp - iter->timestamp ) / SECONDS_FROM_MICROSECONDS );
       
   325         DEBUG1( "core_scan_list_c::print_contents() - tags 0x%02X",
       
   326             iter->tags );
       
   327 
       
   328         DEBUG( "core_scan_list_c::print_contents()" );
       
   329         
       
   330         size += sizeof( *iter ) + sizeof( *iter->ap_data ) +
       
   331                 sizeof( *iter->ap_data->frame() ) + iter->ap_data->frame()->data_length();
       
   332         }
       
   333 
       
   334     DEBUG2( "core_scan_list_c::print_contents() - total size for scan list is %u bytes with %u AP(s)",
       
   335         size, count() );
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 void core_scan_list_c::get_channels_by_ssid(
       
   342     core_scan_channels_c& channels,
       
   343     const core_ssid_s& ssid )
       
   344     {
       
   345     DEBUG( "core_scan_list_c::get_channels_by_ssid()" );
       
   346     
       
   347     core_type_list_iterator_c<core_scan_list_entry_s> iter( scan_list_m );
       
   348     for( core_scan_list_entry_s* current = iter.first(); current; current = iter.next() )
       
   349         {
       
   350         if ( current->ap_data->ssid() == ssid )
       
   351             {
       
   352             channels.add(
       
   353                 current->ap_data->band(),
       
   354                 current->ap_data->channel() );
       
   355             }
       
   356         }
       
   357 
       
   358     DEBUG2( "core_scan_list_c::get_channels_by_ssid() - channels 0x%02X%02X",
       
   359         channels.channels().channels2dot4ghz[1],
       
   360         channels.channels().channels2dot4ghz[0] );
       
   361     }