wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/src/core_frame_assoc_resp.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:  Parser utility for 802.11 (re-)association response frames.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "core_frame_assoc_resp.h"
       
    20 #include "core_frame_dot11_ie.h"
       
    21 #include "core_tools.h"
       
    22 #include "am_debug.h"
       
    23 
       
    24 const u16_t CORE_FRAME_REASSOC_RESP_LENGTH = 24;
       
    25 const u16_t CORE_FRAME_REASSOC_RESP_IE_INDEX = 6;
       
    26 const u16_t CORE_FRAME_REASSOC_RESP_CAPABILITY_INDEX = 0;
       
    27 const u16_t CORE_FRAME_REASSOC_RESP_STATUS_CODE_INDEX = 2;
       
    28 const u16_t CORE_FRAME_REASSOC_RESP_AID_INDEX = 4;
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 core_frame_assoc_resp_c* core_frame_assoc_resp_c::instance(
       
    36     const core_frame_dot11_c& frame,
       
    37     bool_t is_copied )
       
    38     {
       
    39     DEBUG( "core_frame_assoc_resp_c::instance()" );
       
    40 
       
    41     if ( frame.data_length() < CORE_FRAME_REASSOC_RESP_LENGTH )
       
    42         {
       
    43         DEBUG( "core_frame_assoc_resp_c::instance() - not a valid 802.11 (re-)association frame, frame is too short" );
       
    44         
       
    45         return NULL;
       
    46         }
       
    47 
       
    48     u8_t* buffer = const_cast<u8_t*>( frame.data() );
       
    49     u16_t buffer_length( 0 );
       
    50     if ( is_copied )
       
    51         {
       
    52         buffer_length = frame.data_length();
       
    53         buffer = new u8_t[buffer_length];
       
    54 
       
    55         if ( !buffer )
       
    56             {
       
    57             DEBUG( "core_frame_assoc_resp_c::instance() - not able to allocate buffer for copying" );
       
    58 
       
    59             return NULL;            
       
    60             }
       
    61 
       
    62         core_tools_c::copy(
       
    63             buffer,
       
    64             frame.data(),
       
    65             buffer_length );            
       
    66         }
       
    67 
       
    68     core_frame_assoc_resp_c* instance = new core_frame_assoc_resp_c(
       
    69         frame.data_length(),
       
    70         buffer,
       
    71         buffer_length );
       
    72     if ( !instance )
       
    73         {
       
    74         DEBUG( "core_frame_assoc_resp_c::instance() - unable to create an instance" );
       
    75 
       
    76         if ( is_copied )
       
    77             {
       
    78             delete[] buffer;
       
    79             }
       
    80         
       
    81         return NULL;
       
    82         }
       
    83 
       
    84     if ( instance->type() != core_frame_dot11_c::core_dot11_type_association_resp &&
       
    85          instance->type() != core_frame_dot11_c::core_dot11_type_reassociation_resp )
       
    86         {
       
    87         DEBUG( "core_frame_assoc_resp_c::instance() - not a valid (re-)assocation response frame" );
       
    88         delete instance;
       
    89         
       
    90         return NULL;
       
    91         }
       
    92 
       
    93     return instance;
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 core_frame_assoc_resp_c::~core_frame_assoc_resp_c()
       
   100     {
       
   101     DEBUG( "core_frame_assoc_resp_c::~core_frame_assoc_resp_c()" );
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 u16_t core_frame_assoc_resp_c::capability() const
       
   108     {
       
   109     return core_tools_c::get_u16( payload_data(),
       
   110         CORE_FRAME_REASSOC_RESP_CAPABILITY_INDEX );
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 u16_t core_frame_assoc_resp_c::status_code() const
       
   117     {
       
   118     return core_tools_c::get_u16( payload_data(),
       
   119         CORE_FRAME_REASSOC_RESP_STATUS_CODE_INDEX );
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 u16_t core_frame_assoc_resp_c::aid() const
       
   126     {
       
   127     return core_tools_c::get_u16( payload_data(),
       
   128         CORE_FRAME_REASSOC_RESP_AID_INDEX );
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 u16_t core_frame_assoc_resp_c::first_ie_offset() const
       
   135     {
       
   136     return CORE_FRAME_REASSOC_RESP_IE_INDEX;
       
   137     }    
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 core_frame_assoc_resp_c::core_frame_assoc_resp_c(
       
   143     u16_t data_length,
       
   144     const u8_t* data,
       
   145     u16_t max_data_length ) :
       
   146     core_frame_dot11_c( data_length, data, max_data_length )
       
   147     {
       
   148     DEBUG( "core_frame_assoc_resp_c::core_frame_assoc_resp_c()" );
       
   149     }