wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/src/core_frame_nr_ie.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 Neighbor Report IEs.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "core_frame_nr_ie.h"
       
    20 #include "core_tools.h"
       
    21 #include "core_tools_parser.h"
       
    22 #include "am_debug.h"
       
    23 
       
    24 const u8_t CORE_FRAME_NR_IE_PARAMETER_REQ_MIN_LENGTH = 34;
       
    25 const u8_t CORE_FRAME_NR_IE_PARAMETER_RESP_MIN_LENGTH = 15;
       
    26 const u8_t CORE_FRAME_NR_IE_PARAMETER_BSSID_OFFSET = 2;
       
    27 const u8_t CORE_FRAME_NR_IE_PARAMETER_BSSID_INFO_OFFSET = 8;
       
    28 const u8_t CORE_FRAME_NR_IE_PARAMETER_REGULATORY_CLASS_OFFSET = 12;
       
    29 const u8_t CORE_FRAME_NR_IE_PARAMETER_CHANNEL_NUMBER_OFFSET = 13;
       
    30 const u8_t CORE_FRAME_NR_IE_PARAMETER_PHY_TYPE_OFFSET = 14;
       
    31 
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 core_frame_nr_ie_c* core_frame_nr_ie_c::instance(
       
    37     const core_frame_dot11_ie_c& ie )
       
    38     {
       
    39     if ( ie.data_length() < CORE_FRAME_NR_IE_PARAMETER_RESP_MIN_LENGTH )
       
    40         {
       
    41         DEBUG( "core_frame_nr_ie_c::instance() - not a valid IE, invalid length" );
       
    42 
       
    43         return NULL;
       
    44         }
       
    45 
       
    46     core_frame_nr_ie_c* instance = new core_frame_nr_ie_c(
       
    47         ie.data_length(),
       
    48         ie.data(),
       
    49         0 );
       
    50     
       
    51     if ( !instance )
       
    52         {
       
    53         DEBUG( "core_frame_nr_ie_c::instance() - unable to create an instance" );
       
    54 
       
    55         return NULL;
       
    56         }
       
    57     
       
    58     return instance;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // ---------------------------------------------------------------------------
       
    63 //   
       
    64 core_frame_nr_ie_c* core_frame_nr_ie_c::instance(
       
    65     const core_ssid_s& ssid )
       
    66     {
       
    67     const u8_t max_length = CORE_FRAME_NR_IE_PARAMETER_REQ_MIN_LENGTH;
       
    68     
       
    69     u8_t* buffer = new u8_t[max_length];
       
    70     if ( !buffer )
       
    71         {
       
    72         DEBUG( "core_frame_nr_ie_c::instance() - unable to create the internal buffer" );
       
    73         return NULL;
       
    74         }
       
    75 
       
    76     core_frame_nr_ie_c* instance =
       
    77         new core_frame_nr_ie_c( 0, buffer, max_length );
       
    78     
       
    79     if ( !instance )
       
    80         {
       
    81         DEBUG( "core_frame_nr_ie_c::instance() - unable to create an instance" );
       
    82         delete [] buffer;
       
    83 
       
    84         return NULL;
       
    85         }
       
    86 
       
    87     instance->generate( ssid );
       
    88 
       
    89     return instance;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void core_frame_nr_ie_c::generate(
       
    96     const core_ssid_s& ssid )
       
    97     {
       
    98     ASSERT( !data_length_m );
       
    99     ASSERT( max_data_length_m );
       
   100 
       
   101     core_frame_dot11_ie_c::generate( core_frame_dot11_ie_c::core_frame_dot11_ie_element_id_ssid );
       
   102 
       
   103     // SSID
       
   104     core_tools_c::fillz(
       
   105         &data_m[data_length_m],
       
   106         MAX_SSID_LEN );
       
   107     core_tools_c::copy(
       
   108         &data_m[data_length_m],
       
   109         &ssid.ssid[0],
       
   110         ssid.length );
       
   111     data_length_m += MAX_SSID_LEN;
       
   112     
       
   113     set_length( data_length_m );
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // ---------------------------------------------------------------------------
       
   118 //       
       
   119 core_frame_nr_ie_c::~core_frame_nr_ie_c()
       
   120     {
       
   121     DEBUG1( "core_frame_nr_ie_c::~core_frame_nr_ie_c() @ 0x%08X", this );
       
   122     DEBUG1( "core_frame_nr_ie_c::~core_frame_nr_ie_c() - data @ 0x%08X", data_m );
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 core_mac_address_s core_frame_nr_ie_c::bssid() const
       
   129     {
       
   130     core_mac_address_s mac_addr( ZERO_MAC_ADDR );
       
   131     core_tools_c::copy( &mac_addr, &data_m[CORE_FRAME_NR_IE_PARAMETER_BSSID_OFFSET], sizeof( core_mac_address_s ) );
       
   132     return mac_addr;
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 u32_t core_frame_nr_ie_c::bssid_info() const
       
   139     {
       
   140     return core_tools_c::get_u32(
       
   141         data_m,
       
   142         CORE_FRAME_NR_IE_PARAMETER_BSSID_INFO_OFFSET );
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 u8_t core_frame_nr_ie_c::regulatory_class() const
       
   149     {
       
   150     return data_m[CORE_FRAME_NR_IE_PARAMETER_REGULATORY_CLASS_OFFSET];
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 u8_t core_frame_nr_ie_c::channel_number() const
       
   157     {
       
   158     return data_m[CORE_FRAME_NR_IE_PARAMETER_CHANNEL_NUMBER_OFFSET];
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 u8_t core_frame_nr_ie_c::phy_type() const
       
   165     {
       
   166     return data_m[CORE_FRAME_NR_IE_PARAMETER_PHY_TYPE_OFFSET];
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 core_frame_nr_ie_c::core_frame_nr_ie_c(
       
   173     u16_t data_length,
       
   174     const u8_t* data,
       
   175     u16_t max_data_length ) :
       
   176     core_frame_dot11_ie_c( data_length, data, max_data_length )
       
   177     {
       
   178     }