wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/src/core_operation_update_tx_rate_policies.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Statemachine for updating the currently active TX rate policies.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 3 %
       
    20 */
       
    21 
       
    22 #include "core_operation_update_tx_rate_policies.h"
       
    23 #include "core_tx_rate_policies.h"
       
    24 #include "core_frame_dot11_ie.h"
       
    25 #include "core_server.h"
       
    26 #include "core_tools_parser.h"
       
    27 #include "core_tools.h"
       
    28 #include "am_debug.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 core_operation_update_tx_rate_policies_c::core_operation_update_tx_rate_policies_c(
       
    36     u32_t request_id,
       
    37     core_server_c* server,
       
    38     abs_core_driverif_c* drivers,
       
    39     abs_core_server_callback_c* adaptation,
       
    40     core_ap_data_c& ap_data ) :
       
    41     core_operation_base_c( core_operation_scan, request_id, server, drivers, adaptation,
       
    42         core_base_flag_only_one_instance ),
       
    43     current_ap_m( &ap_data )
       
    44     {
       
    45     DEBUG( "core_operation_update_tx_rate_policies_c::core_operation_update_tx_rate_policies_c()" );
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 core_operation_update_tx_rate_policies_c::core_operation_update_tx_rate_policies_c(
       
    52     u32_t request_id,
       
    53     core_server_c* server,
       
    54     abs_core_driverif_c* drivers,
       
    55     abs_core_server_callback_c* adaptation ) :
       
    56     core_operation_base_c( core_operation_scan, request_id, server, drivers, adaptation,
       
    57         core_base_flag_only_one_instance ),
       
    58     current_ap_m( NULL )
       
    59     {
       
    60     DEBUG( "core_operation_update_tx_rate_policies_c::core_operation_update_tx_rate_policies_c()" );
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 core_operation_update_tx_rate_policies_c::~core_operation_update_tx_rate_policies_c()
       
    67     {
       
    68     DEBUG( "core_operation_update_tx_rate_policies_c::~core_operation_update_tx_rate_policies_c()" );
       
    69 
       
    70     current_ap_m = NULL;
       
    71     }
       
    72     
       
    73 // ---------------------------------------------------------------------------
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 core_error_e core_operation_update_tx_rate_policies_c::next_state()
       
    77     {
       
    78     DEBUG( "core_operation_update_tx_rate_policies_c::next_state()" );
       
    79 
       
    80     switch ( operation_state_m )
       
    81         {
       
    82         case core_state_init:
       
    83             {
       
    84             operation_state_m = core_state_success;
       
    85 
       
    86             if( !server_m->get_core_settings().is_driver_loaded() )
       
    87                 {
       
    88                 DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - driver not loaded, completing operation" );
       
    89                 return core_error_ok;
       
    90                 }
       
    91 
       
    92             if ( !current_ap_m )
       
    93                 {
       
    94                 if ( !server_m->get_connection_data() ||
       
    95                      !server_m->get_connection_data()->current_ap_data() )
       
    96                     {
       
    97                     DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - no current AP defined, completing operation" );
       
    98                     return core_error_ok;                    
       
    99                     }
       
   100 
       
   101                 current_ap_m = server_m->get_connection_data()->current_ap_data();
       
   102                 }
       
   103 
       
   104             u32_t basic_rates( 0 );
       
   105             u32_t supported_rates( 0 );
       
   106             for( core_frame_dot11_ie_c* ie = current_ap_m->frame()->first_ie(); ie; ie = current_ap_m->frame()->next_ie() )
       
   107                 {
       
   108                 if ( ie->element_id() == core_frame_dot11_ie_c::core_frame_dot11_ie_element_id_supported_rates ||
       
   109                      ie->element_id() == core_frame_dot11_ie_c::core_frame_dot11_ie_element_id_extended_rates )
       
   110                     {
       
   111                     u32_t temp_basic_rates( 0 );
       
   112                     u32_t temp_supported_rates( 0 );
       
   113 
       
   114                     core_tools_parser_c::parse_rates(
       
   115                         ie->data() + CORE_FRAME_DOT11_IE_HEADER_LENGTH,
       
   116                         ie->length(),
       
   117                         temp_basic_rates,
       
   118                         temp_supported_rates );
       
   119 
       
   120                     basic_rates |= temp_basic_rates;
       
   121                     supported_rates |= temp_supported_rates;
       
   122                     }
       
   123 
       
   124                 delete ie;
       
   125                 }
       
   126 
       
   127             DEBUG_RATES( "core_operation_update_tx_rate_policies_c::next_state() - AP basic rates: ",
       
   128                 basic_rates );
       
   129             DEBUG_RATES( "core_operation_update_tx_rate_policies_c::next_state() - AP supported rates: ",
       
   130                 supported_rates );
       
   131 
       
   132             core_ap_type_e current_ap_type(
       
   133                 core_ap_type_802p11bg );
       
   134 
       
   135             /**
       
   136              * AP is 802.11b only if only 802.11b rates are advertised as supported rates.
       
   137              */
       
   138             if ( !( supported_rates & ~CORE_TX_RATES_802P11B ) )
       
   139                 {
       
   140                 current_ap_type = core_ap_type_802p11b_only;
       
   141                 }
       
   142             /**
       
   143              * AP is 802.11g only if any of the 802.11g rates is a basic rate.
       
   144              */
       
   145             else if ( basic_rates & CORE_TX_RATES_802P11G )
       
   146                 {
       
   147                 current_ap_type = core_ap_type_802p11g_only;
       
   148                 }
       
   149 
       
   150             /**
       
   151              * It's possible AP has given us TX rates to be used.
       
   152              */
       
   153             u32_t override_voice_rates( 0 );
       
   154             core_traffic_stream_list_c& ts_list(
       
   155                 server_m->get_connection_data()->traffic_stream_list() );
       
   156             core_traffic_stream_c* iter = ts_list.first();
       
   157             while( iter && !override_voice_rates )
       
   158                 {
       
   159                 if ( core_tools_c::convert_user_priority_to_ac( iter->user_priority() ) == core_access_class_voice &&
       
   160                      iter->status() == core_traffic_stream_status_active &&
       
   161                      iter->override_rates() )
       
   162                     {
       
   163                     override_voice_rates = iter->override_rates();
       
   164                     DEBUG_RATES( "core_operation_update_tx_rate_policies_c::next_state() - AP override rates for Voice: ",
       
   165                         override_voice_rates );
       
   166                     }
       
   167 
       
   168                 iter = ts_list.next();
       
   169                 }
       
   170 
       
   171             core_tx_rate_policies_s policies;
       
   172             core_tx_rate_policy_mappings_s mappings;
       
   173 
       
   174             if ( server_m->get_core_settings().is_bt_connection_established() )
       
   175                 {
       
   176                 policies.policy_count = 1;
       
   177                 mappings.policy_for_best_effort = 0;
       
   178                 mappings.policy_for_background = 0;
       
   179                 mappings.policy_for_video = 0;
       
   180                 mappings.policy_for_voice = 0;          
       
   181 
       
   182                 if ( current_ap_type == core_ap_type_802p11b_only )
       
   183                     {
       
   184                     DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - using 802.11b-only BT TX rate policy" );
       
   185 
       
   186                     policies.policy[0] = TX_RATE_POLICY_BLUETOOTH_B;
       
   187                     }
       
   188                 else if ( current_ap_type == core_ap_type_802p11g_only )
       
   189                     {
       
   190                     DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - using 802.11g-only BT TX rate policy" );
       
   191 
       
   192                     policies.policy[0] = TX_RATE_POLICY_BLUETOOTH_G;
       
   193                     }
       
   194                 else
       
   195                     {
       
   196                     DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - using 802.11bg BT TX rate policy" );
       
   197 
       
   198                     policies.policy[0] = TX_RATE_POLICY_BLUETOOTH_BG;
       
   199                     }
       
   200                 }
       
   201             else
       
   202                 {
       
   203                 policies.policy_count = 2;
       
   204                 mappings.policy_for_best_effort = 0;
       
   205                 mappings.policy_for_background = 0;
       
   206                 mappings.policy_for_video = 0;
       
   207                 mappings.policy_for_voice = 1;
       
   208 
       
   209                 if ( current_ap_type == core_ap_type_802p11b_only )
       
   210                     {
       
   211                     DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - using 802.11b-only default and voice TX rate policy" );
       
   212 
       
   213                     policies.policy[0] = TX_RATE_POLICY_B;
       
   214                     policies.policy[1] = TX_RATE_POLICY_VOICE_B;
       
   215                     }
       
   216                 else if ( current_ap_type == core_ap_type_802p11g_only )
       
   217                     {
       
   218                     DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - using 802.11g-only default and voice TX rate policy" );
       
   219 
       
   220                     policies.policy[0] = TX_RATE_POLICY_G;
       
   221                     policies.policy[1] = TX_RATE_POLICY_VOICE_G;
       
   222                     }
       
   223                 else
       
   224                     {
       
   225                     DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - using 802.11bg default and voice TX rate policy" );
       
   226 
       
   227                     policies.policy[0] = TX_RATE_POLICY_BG;
       
   228                     policies.policy[1] = TX_RATE_POLICY_VOICE_BG;
       
   229                     }                    
       
   230 
       
   231                 if ( override_voice_rates )
       
   232                     {
       
   233                     DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - generating a new voice TX rate policy based on override rates" );
       
   234                     DEBUG_RATES( "core_operation_update_tx_rate_policies_c::next_state() - initial rate: ",
       
   235                         core_tools_c::highest_tx_rate( override_voice_rates ) );
       
   236 
       
   237                     core_tx_rate_policy_s voice_policy;
       
   238                     core_tools_c::fillz(
       
   239                         &voice_policy,
       
   240                         sizeof( voice_policy ) );
       
   241                     voice_policy =
       
   242                         core_tools_c::convert_tx_rates_to_tx_policy( override_voice_rates );
       
   243                     voice_policy.initial_tx_rate =
       
   244                         core_tools_c::highest_tx_rate( override_voice_rates );
       
   245                     policies.policy[1] = voice_policy;
       
   246                     }
       
   247                 }
       
   248 
       
   249             /**
       
   250              * Fill in the default retry limits if not overridden by the policy.
       
   251              */
       
   252             for ( u8_t idx( 0 ); idx < policies.policy_count; ++idx )
       
   253                 {
       
   254                 if ( !policies.policy[idx].short_retry_limit )
       
   255                     {
       
   256                     policies.policy[idx].short_retry_limit =
       
   257                         server_m->get_device_settings().short_retry;
       
   258                     }
       
   259                 if ( ! policies.policy[idx].long_retry_limit )
       
   260                     {
       
   261                     policies.policy[idx].long_retry_limit =
       
   262                         server_m->get_device_settings().long_retry;
       
   263                     }
       
   264                 }
       
   265 
       
   266             DEBUG( "core_operation_update_rxtx_parameters_c::next_state() - setting TX rate policies" );
       
   267 
       
   268             drivers_m->set_tx_rate_policies(
       
   269                 request_id_m,
       
   270                 policies,
       
   271                 mappings );
       
   272 
       
   273             break;
       
   274             }
       
   275         case core_state_success:
       
   276             {
       
   277             DEBUG( "core_operation_update_tx_rate_policies_c::next_state() - TX rate policies set" );
       
   278 
       
   279             return core_error_ok;
       
   280             }
       
   281         default:
       
   282             {
       
   283             ASSERT( false_t );
       
   284             }
       
   285         }
       
   286 
       
   287     return core_error_request_pending;
       
   288     }