wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/src/core_frame_action_rm.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Class for parsing and generating 802.11 action frames in RM category.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "core_frame_action_rm.h"
       
    20 #include "core_frame_rm_ie.h"
       
    21 #include "core_tools.h"
       
    22 #include "am_debug.h"
       
    23 
       
    24 const u16_t CORE_FRAME_ACTION_RM_MIN_LENGTH = 28;
       
    25 const u16_t CORE_FRAME_ACTION_RM_LENGTH = 400;
       
    26 const u16_t CORE_FRAME_ACTION_RM_TOKEN_INDEX = 26;
       
    27 const u16_t CORE_FRAME_ACTION_RM_NBR_OF_REPETITIONS_INDEX = 27;
       
    28 const u16_t CORE_FRAME_ACTION_RM_IE_INDEX = 5;
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 core_frame_action_rm_c* core_frame_action_rm_c::instance(
       
    36     const core_frame_action_c& frame,
       
    37     bool_t is_copied )
       
    38     {
       
    39     DEBUG( "core_frame_action_rm_c::instance()" );
       
    40     DEBUG1( "core_frame_action_rm_c::instance() - is_copied %u",
       
    41         is_copied );  
       
    42 
       
    43     if ( frame.data_length() < CORE_FRAME_ACTION_RM_MIN_LENGTH )
       
    44         {
       
    45         DEBUG( "core_frame_action_rm_c::instance() - not a valid 802.11 frame, frame is too short" );
       
    46         
       
    47         return NULL;
       
    48         }
       
    49 
       
    50     u8_t* buffer = const_cast<u8_t*>( frame.data() );
       
    51     u16_t buffer_length( 0 );
       
    52 
       
    53     if( is_copied )
       
    54         {
       
    55         buffer_length = frame.data_length();
       
    56         buffer = new u8_t[buffer_length];
       
    57         
       
    58         if( !buffer )
       
    59             {
       
    60             DEBUG( "core_frame_action_rm_c::instance() - not able to allocate buffer for copying" );
       
    61         
       
    62             return NULL;            
       
    63             }
       
    64 
       
    65         core_tools_c::copy( buffer, frame.data(), buffer_length );
       
    66         }
       
    67 
       
    68     core_frame_action_rm_c* instance = new core_frame_action_rm_c(
       
    69         buffer_length,
       
    70         buffer,
       
    71         buffer_length );
       
    72 
       
    73     if ( !instance )
       
    74         {
       
    75         DEBUG( "core_frame_action_rm_c::instance() - unable to create an instance" );
       
    76         delete[] buffer;
       
    77         buffer = NULL;
       
    78         
       
    79         return NULL;
       
    80         }
       
    81 
       
    82     return instance;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 core_frame_action_rm_c* core_frame_action_rm_c::instance(
       
    89     u16_t duration,
       
    90     const core_mac_address_s& destination,
       
    91     const core_mac_address_s& source,
       
    92     const core_mac_address_s& bssid,
       
    93     u16_t sequence_control,
       
    94     u8_t action_type,
       
    95     u8_t dialog_token,
       
    96     const core_frame_rm_ie_c* rm_ie )
       
    97     {
       
    98     const u16_t max_data_length = CORE_FRAME_ACTION_RM_LENGTH;
       
    99 
       
   100     u8_t* buffer = new u8_t[max_data_length];
       
   101     if ( !buffer )
       
   102         {
       
   103         DEBUG( "core_frame_action_rm_c::instance() - unable create the internal buffer" );
       
   104         return NULL;
       
   105         }
       
   106 
       
   107     core_frame_action_rm_c* instance =
       
   108         new core_frame_action_rm_c( 0, buffer, max_data_length );
       
   109     if ( !instance )
       
   110         {
       
   111         DEBUG( "core_frame_action_rm_c::instance() - unable to create an instance" );
       
   112         delete[] buffer;
       
   113         buffer = NULL;
       
   114 
       
   115         return NULL;
       
   116         }
       
   117 
       
   118     instance->generate(
       
   119         duration,
       
   120         destination,
       
   121         source,
       
   122         bssid,
       
   123         sequence_control,
       
   124         action_type,
       
   125         dialog_token,
       
   126         rm_ie );
       
   127 
       
   128     return instance;    
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 core_frame_action_rm_c::~core_frame_action_rm_c()
       
   135     {
       
   136     DEBUG1( "core_frame_action_rm_c::~core_frame_action_rm_c() @ 0x%08X", this );
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 u8_t core_frame_action_rm_c::dialog_token() const
       
   143     {
       
   144     return data_m[CORE_FRAME_ACTION_RM_TOKEN_INDEX];
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 u16_t core_frame_action_rm_c::first_ie_offset() const
       
   151     {
       
   152     return CORE_FRAME_ACTION_RM_IE_INDEX;
       
   153     }    
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 u16_t core_frame_action_rm_c::nbr_of_repetitions() const
       
   159     {
       
   160     u16_t repetitions( 0 );
       
   161     core_tools_c::copy( &repetitions, &data_m[CORE_FRAME_ACTION_RM_NBR_OF_REPETITIONS_INDEX], sizeof( repetitions ) );
       
   162 
       
   163     return repetitions;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void core_frame_action_rm_c::generate(
       
   170     u16_t duration,
       
   171     const core_mac_address_s& destination,
       
   172     const core_mac_address_s& source,
       
   173     const core_mac_address_s& bssid,
       
   174     u16_t sequence_control,
       
   175     u8_t action_type,
       
   176     u8_t dialog_token,
       
   177     const core_frame_rm_ie_c* rm_ie )
       
   178     {
       
   179     ASSERT( !data_length_m );
       
   180     ASSERT( max_data_length_m );
       
   181     ASSERT( rm_ie );
       
   182 
       
   183     core_frame_action_c::generate(            
       
   184         duration,
       
   185         destination,
       
   186         source,
       
   187         bssid,
       
   188         sequence_control,
       
   189         core_frame_action_c::core_dot11_action_category_rm );
       
   190     
       
   191     // Action Type
       
   192     data_m[data_length_m++] = action_type;
       
   193 
       
   194     // Dialog Token
       
   195     data_m[data_length_m++] = dialog_token;
       
   196 
       
   197     // IE
       
   198     core_tools_c::copy(
       
   199         &data_m[data_length_m],
       
   200         rm_ie->data(),
       
   201         rm_ie->data_length() );
       
   202     data_length_m += rm_ie->data_length();
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 core_frame_action_rm_c::core_frame_action_rm_c(
       
   209     u16_t data_length,
       
   210     const u8_t* data,
       
   211     u16_t max_data_length ) :
       
   212     core_frame_action_c( data_length, data, max_data_length )
       
   213     {
       
   214     DEBUG1( "core_frame_action_rm_c::core_frame_action_rm_c() @ 0x%08X", this );
       
   215     }