wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/src/core_frame_beacon.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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 beacon and probe response frames
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "core_frame_beacon.h"
       
    20 #include "core_frame_dot11_ie.h"
       
    21 #include "core_tools.h"
       
    22 #include "am_debug.h"
       
    23 
       
    24 const u16_t CORE_BEACON_LENGTH = 36;
       
    25 const u16_t CORE_BEACON_TIMESTAMP_INDEX = 0;
       
    26 const u16_t CORE_BEACON_BEACON_INTERVAL_INDEX = 8;
       
    27 const u16_t CORE_BEACON_CAPABILITY_INDEX = 10;
       
    28 const u16_t CORE_BEACON_IE_INDEX = 12;
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 core_frame_beacon_c* core_frame_beacon_c::instance(
       
    36     const core_frame_dot11_c& frame,
       
    37     bool_t is_copied )
       
    38     {
       
    39     DEBUG( "core_frame_beacon_c::instance()" );
       
    40 
       
    41     if ( frame.data_length() < CORE_BEACON_LENGTH )
       
    42         {
       
    43         DEBUG( "core_frame_beacon_c::instance() - not a valid 802.11 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 
       
    51     if ( is_copied )
       
    52         {
       
    53         buffer_length = frame.data_length();
       
    54         buffer = new u8_t[buffer_length];
       
    55         
       
    56         if ( !buffer )
       
    57             {
       
    58             DEBUG( "core_frame_beacon_c::instance() - not able to allocate buffer for copying" );
       
    59         
       
    60             return NULL;            
       
    61             }
       
    62 
       
    63         core_tools_c::copy(
       
    64             buffer,
       
    65             frame.data(),
       
    66             buffer_length );            
       
    67         }
       
    68 
       
    69     core_frame_beacon_c* instance = new core_frame_beacon_c(
       
    70         frame.data_length(),
       
    71         buffer,
       
    72         buffer_length );
       
    73     if ( !instance )
       
    74         {
       
    75         DEBUG( "core_frame_beacon_c::instance() - unable to create an instance" );
       
    76         
       
    77         if ( is_copied )
       
    78             {
       
    79             delete[] buffer;
       
    80             }
       
    81         
       
    82         return NULL;
       
    83         }
       
    84 
       
    85     if ( instance->type() != core_frame_dot11_c::core_dot11_type_beacon &&
       
    86          instance->type() != core_frame_dot11_c::core_dot11_type_probe_resp )
       
    87         {
       
    88         DEBUG( "core_frame_beacon_c::instance() - not a valid beacon or probe response frame" );
       
    89         delete instance;
       
    90         
       
    91         return NULL;
       
    92         }
       
    93     
       
    94     return instance;
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 core_frame_beacon_c::~core_frame_beacon_c()
       
   101     {
       
   102     DEBUG( "core_frame_beacon_c::~core_frame_beacon_c()" );
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 u16_t core_frame_beacon_c::first_ie_offset() const
       
   109     {
       
   110     return CORE_BEACON_IE_INDEX;
       
   111     }    
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 core_tsf_value_s core_frame_beacon_c::timestamp() const
       
   117     {
       
   118     core_tsf_value_s timestamp;
       
   119     
       
   120     core_tools_c::copy(
       
   121         &timestamp.tsf[0],
       
   122         payload_data() + CORE_BEACON_TIMESTAMP_INDEX,
       
   123         TSF_VALUE_LEN );
       
   124         
       
   125     return timestamp;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 u16_t core_frame_beacon_c::beacon_interval() const
       
   132     {
       
   133     return core_tools_c::get_u16( payload_data(),
       
   134         CORE_BEACON_BEACON_INTERVAL_INDEX );
       
   135     }
       
   136     
       
   137 // ---------------------------------------------------------------------------
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 u16_t core_frame_beacon_c::capability() const
       
   141     {
       
   142     return core_tools_c::get_u16( payload_data(),
       
   143         CORE_BEACON_CAPABILITY_INDEX );
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 core_frame_beacon_c::core_frame_beacon_c(
       
   150     u16_t data_length,
       
   151     const u8_t* data,
       
   152     u16_t max_data_length ) :
       
   153     core_frame_dot11_c( data_length, data, max_data_length )
       
   154     {
       
   155     DEBUG( "core_frame_beacon_c::core_frame_beacon_c()" );
       
   156     }