hotspotfw/hsserver/src/hssscaninfoie.cpp
changeset 0 56b72877c1cb
equal deleted inserted replaced
-1:000000000000 0:56b72877c1cb
       
     1 /*
       
     2 * Copyright (c) 2002-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 "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:   Implementation of the ScanInfoIe class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "hssscaninfoie.h"
       
    21 
       
    22 // Defines the id byte of the RSN Information Element.
       
    23 const TUint8 SCANINFOIE_RSNIE_ID = 48;
       
    24 
       
    25 // Defines the static offsets for different fields in RSN IE.
       
    26 const TUint32 SCANINFOIE_RSNIE_GROUP_SUITE_OFFSET = 2;
       
    27 const TUint32 SCANINFOIE_RSNIE_PAIRWISE_SUITE_COUNT_OFFSET = 6;
       
    28 const TUint32 SCANINFOIE_RSNIE_PAIRWISE_SUITE_OFFSET = 8;
       
    29 
       
    30 // Defines the OUIs used in RSN IEs.
       
    31 const TUint32 SCANINFOIE_OUI_LENGTH = 4;
       
    32 const TUint8 SCANINFOIE_RSNIE_OUI_CCMP[] = { 0x00, 0x0F, 0xAC, 0x04 };
       
    33 const TUint8 SCANINFOIE_RSNIE_OUI_EAP[] = { 0x00, 0x0F, 0xAC, 0x01 };
       
    34 const TUint8 SCANINFOIE_RSNIE_OUI_PSK[] = { 0x00, 0x0F, 0xAC, 0x02 };
       
    35 
       
    36 // Defines the static offsets for different fields in RSN IE.
       
    37 const TUint32 SCANINFOIE_WPAIE_PAIRWISE_SUITE_COUNT_OFFSET = 10;
       
    38 const TUint32 SCANINFOIE_WPAIE_PAIRWISE_SUITE_OFFSET = 12;
       
    39 
       
    40 // Defines the OUIs used in WPA IEs.
       
    41 const TUint8 SCANINFOIE_WPAIE_OUI_EAP[] = { 0x00, 0x50, 0xF2, 0x01 };
       
    42 const TUint8 SCANINFOIE_WPAIE_OUI_PSK[] = { 0x00, 0x50, 0xF2, 0x02 };
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // ScanInfoIe::ScanInfoIe
       
    48 // C++ default constructor can NOT contain any code, that
       
    49 // might leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 HssScanInfoIe::HssScanInfoIe()
       
    53     {
       
    54     }
       
    55     
       
    56 // Destructor
       
    57 HssScanInfoIe::~HssScanInfoIe()
       
    58     {    
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // ScanInfoIe::SecurityMode
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 HssSecurityMode HssScanInfoIe::SecurityMode(
       
    66     HssScanInfo& info )
       
    67     {
       
    68     TUint8 wpaie_length( 0 );
       
    69     const TUint8* wpaie_data = NULL;
       
    70     TUint8 rsnie_length( 0 );
       
    71     const TUint8* rsnie_data = NULL;
       
    72     
       
    73     info.InformationElement( SCANINFOIE_RSNIE_ID, rsnie_length, &rsnie_data );
       
    74     info.WpaIE( wpaie_length, &wpaie_data );
       
    75 
       
    76     if ( !info.Privacy() )
       
    77         {
       
    78         if ( !wpaie_length && !rsnie_length )
       
    79             {
       
    80             return HssSecurityModeOpen;
       
    81             }
       
    82         return HssSecurityMode802_1x;
       
    83         }
       
    84         
       
    85     if ( !wpaie_length && !rsnie_length )
       
    86         {
       
    87         return HssSecurityModeWep;
       
    88         }
       
    89 
       
    90     if ( rsnie_length )
       
    91         {        
       
    92         if ( IsKeyManagement(
       
    93             HssScanInfoIeTypeRsn,
       
    94             HssScanInfoIeKeyManagementPsk,
       
    95             rsnie_length,
       
    96             rsnie_data ) )
       
    97             {
       
    98             if ( IsWpa2Ciphers(
       
    99                 HssScanInfoIeTypeRsn,
       
   100                 rsnie_length,
       
   101                 rsnie_data ) )
       
   102                 {
       
   103                 return HssSecurityModeWpa2Psk;
       
   104                 }
       
   105             
       
   106             return HssSecurityModeWpaPsk;            
       
   107             }
       
   108         else if ( IsKeyManagement(
       
   109             HssScanInfoIeTypeRsn,
       
   110             HssScanInfoIeKeyManagementEap,
       
   111             rsnie_length,
       
   112             rsnie_data ) )
       
   113             {
       
   114             if ( IsWpa2Ciphers(
       
   115                 HssScanInfoIeTypeRsn,
       
   116                 rsnie_length,
       
   117                 rsnie_data ) )
       
   118                 {                
       
   119                 return HssSecurityModeWpa2Eap;
       
   120                 }
       
   121             
       
   122             return HssSecurityModeWpaEap;            
       
   123             }                        
       
   124         }
       
   125         
       
   126     if ( wpaie_length )
       
   127         {
       
   128         if ( IsKeyManagement(
       
   129             HssScanInfoIeTypeWpa,
       
   130             HssScanInfoIeKeyManagementPsk,
       
   131             wpaie_length,
       
   132             wpaie_data ) )
       
   133             {
       
   134             return HssSecurityModeWpaPsk;            
       
   135             }
       
   136         else if ( IsKeyManagement(
       
   137             HssScanInfoIeTypeWpa,
       
   138             HssScanInfoIeKeyManagementEap,
       
   139             wpaie_length,
       
   140             wpaie_data ) )
       
   141             {
       
   142             return HssSecurityModeWpaEap;            
       
   143             }        
       
   144         }
       
   145     
       
   146     return HssSecurityMode802_1x;
       
   147     }
       
   148  
       
   149 // -----------------------------------------------------------------------------
       
   150 // ScanInfoIe::Compare
       
   151 // -----------------------------------------------------------------------------
       
   152 //   
       
   153 TInt HssScanInfoIe::Compare(
       
   154     const unsigned char* pl,
       
   155     int ll, 
       
   156     const unsigned char* pr, 
       
   157     int rl )
       
   158     {
       
   159     if ( ll != rl )
       
   160         return ll - rl;
       
   161 
       
   162     if ( pl == pr )
       
   163         return 0;
       
   164 
       
   165     for ( int i( 0 ); i < ll; ++i )
       
   166         if ( *(pl+i) != *(pr+i) )
       
   167             return *(pl+i) - *(pr+i);
       
   168 
       
   169     return 0;    
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // ScanInfoIe::IsKeyManagement
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 
       
   177 TBool HssScanInfoIe::IsKeyManagement(
       
   178     HssScanInfoIeType ie_type,
       
   179     HssScanInfoIeKeyManagement key_type,
       
   180     TUint8 /* ie_length */,
       
   181     const TUint8* ie_data )
       
   182     {
       
   183     const TUint8* key_data = NULL;
       
   184     const TUint8* key_comp = NULL;
       
   185    
       
   186     if ( ie_type == HssScanInfoIeTypeRsn )
       
   187         {
       
   188         if ( key_type == HssScanInfoIeKeyManagementEap )
       
   189             {
       
   190             key_comp = &SCANINFOIE_RSNIE_OUI_EAP[0];
       
   191             }
       
   192         else
       
   193             {
       
   194             key_comp = &SCANINFOIE_RSNIE_OUI_PSK[0];
       
   195             }
       
   196         TUint32 suites( *( ie_data + SCANINFOIE_RSNIE_PAIRWISE_SUITE_COUNT_OFFSET ) );
       
   197         key_data = ie_data + SCANINFOIE_RSNIE_PAIRWISE_SUITE_OFFSET +
       
   198             ( suites * SCANINFOIE_OUI_LENGTH );
       
   199         }
       
   200     else
       
   201         {
       
   202         if ( key_type == HssScanInfoIeKeyManagementEap )
       
   203             {
       
   204             key_comp = &SCANINFOIE_WPAIE_OUI_EAP[0];
       
   205             }
       
   206         else
       
   207             {
       
   208             key_comp = &SCANINFOIE_WPAIE_OUI_PSK[0];
       
   209             }
       
   210         TUint32 suites( *( ie_data + SCANINFOIE_WPAIE_PAIRWISE_SUITE_COUNT_OFFSET ) );
       
   211         key_data = ie_data + SCANINFOIE_WPAIE_PAIRWISE_SUITE_OFFSET +
       
   212             ( suites * SCANINFOIE_OUI_LENGTH );        
       
   213         }
       
   214     TUint16 key_suites( *key_data );
       
   215     key_data += sizeof( key_suites );
       
   216 
       
   217     while ( key_suites-- )
       
   218         {
       
   219         if ( !Compare(
       
   220             key_data + ( key_suites * SCANINFOIE_OUI_LENGTH ), SCANINFOIE_OUI_LENGTH,
       
   221             key_comp, SCANINFOIE_OUI_LENGTH ) )
       
   222             {
       
   223             return true;
       
   224             }
       
   225         }
       
   226 
       
   227     return false;
       
   228     };
       
   229    
       
   230 // -----------------------------------------------------------------------------
       
   231 // ScanInfoIe::IsWpa2Ciphers
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TBool HssScanInfoIe::IsWpa2Ciphers(
       
   235     HssScanInfoIeType ie_type,
       
   236     TUint8 /* ie_length */,
       
   237     const TUint8* ie_data )
       
   238     {
       
   239     /**
       
   240     * WPA IE is not used in WPA2
       
   241     */    
       
   242     if ( ie_type == HssScanInfoIeTypeWpa )
       
   243         {
       
   244         return false;
       
   245         }
       
   246 
       
   247     const TUint8* cipher =
       
   248         ie_data + SCANINFOIE_RSNIE_GROUP_SUITE_OFFSET;
       
   249 
       
   250     if ( Compare(
       
   251         cipher, SCANINFOIE_OUI_LENGTH,
       
   252         &SCANINFOIE_RSNIE_OUI_CCMP[0], SCANINFOIE_OUI_LENGTH ) )
       
   253         {
       
   254         return false;
       
   255         }
       
   256 
       
   257     TUint32 suites( *( ie_data + SCANINFOIE_RSNIE_PAIRWISE_SUITE_COUNT_OFFSET ) );
       
   258     cipher = ie_data + SCANINFOIE_RSNIE_PAIRWISE_SUITE_OFFSET;
       
   259 
       
   260     while ( suites-- )
       
   261         {
       
   262         if ( !Compare(
       
   263             cipher + ( suites * SCANINFOIE_OUI_LENGTH ), SCANINFOIE_OUI_LENGTH,
       
   264             &SCANINFOIE_RSNIE_OUI_CCMP[0], SCANINFOIE_OUI_LENGTH ) )
       
   265             {
       
   266             return true;
       
   267             }
       
   268         }
       
   269 
       
   270     return false;
       
   271     }