wlanutilities/wlansniffer/wlaninfo/src/wsfwlaninfo.cpp
branchRCL_3
changeset 25 f28ada11abbf
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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 TWsfWlanInfo
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  EXTERNAL INCLUDES
       
    21 #include <utf.h>
       
    22 #include <s32strm.h>
       
    23 
       
    24 //  CLASS HEADER
       
    25 #include "wsfwlaninfo.h"
       
    26 
       
    27 
       
    28 using namespace CMManager;
       
    29 
       
    30 
       
    31 // Percentage max value
       
    32 static const TInt KMaxPercentage = 100;
       
    33 
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // TWsfWlanInfo::TWsfWlanInfo
       
    38 // ---------------------------------------------------------------------------
       
    39 //    
       
    40 EXPORT_C TWsfWlanInfo::TWsfWlanInfo():
       
    41     iSsid( KNullDesC8 ),
       
    42 	iStrengthLevel( EWlanSignalUnavailable ),
       
    43     iSecurityMode( EWlanSecModeOpen ),
       
    44     iVisibility( EFalse ),
       
    45     iNetMode( EAdhoc ),
       
    46     iIapId( 0 ),
       
    47     iCoverage( 0 ),
       
    48     iTransferRate( 0 ),
       
    49     iConnectionState( ENotConnected ),
       
    50     iFilterFlags( 0 ),
       
    51     iBrandId( 0 ),
       
    52     iNetworkName( KNullDesC8 ),
       
    53     iPriority ( 0 ),
       
    54     iRawSsid ( KNullDesC8 )
       
    55     {
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // TWsfWlanInfo::TWsfWlanInfo
       
    61 // ---------------------------------------------------------------------------
       
    62 //    
       
    63 EXPORT_C TWsfWlanInfo::TWsfWlanInfo( TDesC8& aSsid,
       
    64                         TUint16 aStrengthLevel,
       
    65                         TWlanSecMode aSecurityMode,
       
    66                         TInt aVisibility,
       
    67                         TWlanNetMode aNetMode,
       
    68                         TUint32 aIapId,
       
    69                         TUint8 aCoverage,
       
    70                         TUint32 aTransferRate ):
       
    71     iSsid( aSsid ),
       
    72     iStrengthLevel( aStrengthLevel ),
       
    73     iSecurityMode( aSecurityMode ),
       
    74     iVisibility( aVisibility ),
       
    75     iNetMode( aNetMode ),
       
    76     iIapId( aIapId ),
       
    77     iCoverage( aCoverage ),
       
    78     iTransferRate( aTransferRate ),
       
    79     iConnectionState( ENotConnected ),
       
    80     iFilterFlags( 0 ),
       
    81     iBrandId( 0 ),
       
    82     iPriority( 0 ),
       
    83     iRawSsid ( KNullDesC8 )
       
    84     {
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // TWsfWlanInfo::GetSsidAsUnicodeLC
       
    89 // ---------------------------------------------------------------------------
       
    90 //    
       
    91 EXPORT_C HBufC* TWsfWlanInfo::GetSsidAsUnicodeLC()
       
    92     {
       
    93     return GetSsidAsUnicodeLC( iSsid );
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // TWsfWlanInfo::GetSsidAsUnicodeLC
       
    99 // ---------------------------------------------------------------------------
       
   100 //    
       
   101 EXPORT_C HBufC* TWsfWlanInfo::GetSsidAsUnicodeLC( const TWlanSsid& aSsid )
       
   102     {
       
   103     HBufC* ssid = HBufC::NewLC( aSsid.Length() );
       
   104     TPtr ptr = ssid->Des();
       
   105     TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8( ptr, aSsid );
       
   106     if ( err != KErrNone )
       
   107         {
       
   108         // If ssid wasn't utf-8 encoded, assume it unicode already
       
   109         // it's not specified how WLAN SSIDs should be encoded.
       
   110         ptr.Copy( aSsid );
       
   111         }
       
   112     return ssid;
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // TWsfWlanInfo::GetSsidAsUtf8LC
       
   118 // ---------------------------------------------------------------------------
       
   119 //    
       
   120 EXPORT_C HBufC8* TWsfWlanInfo::GetSsidAsUtf8LC()
       
   121     {
       
   122     HBufC8* ssid = iSsid.AllocLC();
       
   123     return ssid;
       
   124     }
       
   125 
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // TWsfWlanInfo::InternalizeL
       
   129 // ---------------------------------------------------------------------------
       
   130 //    
       
   131 EXPORT_C void TWsfWlanInfo::InternalizeL( RReadStream& aStream )
       
   132 	{
       
   133 	aStream >> iSsid;
       
   134 	iStrengthLevel = aStream.ReadInt16L();
       
   135 	iSecurityMode = TWlanSecMode( aStream.ReadInt32L() );
       
   136 	iVisibility = aStream.ReadInt8L();
       
   137 	iNetMode = TWlanNetMode( aStream.ReadInt32L() );
       
   138 	iIapId = aStream.ReadInt32L();
       
   139 	iCoverage = aStream.ReadInt8L();
       
   140 	iTransferRate = aStream.ReadInt32L();
       
   141 	iConnectionState = TWsfWlanConnectionState( aStream.ReadInt8L() );
       
   142 	iFilterFlags = aStream.ReadInt8L();
       
   143 	iBrandId = aStream.ReadInt8L();
       
   144 	iPriority = aStream.ReadInt8L();
       
   145 	aStream >> iNetworkName;
       
   146 	aStream >> iRawSsid;
       
   147 	}
       
   148 
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // TWsfWlanInfo::ExternalizeL
       
   152 // ---------------------------------------------------------------------------
       
   153 //    
       
   154 EXPORT_C void TWsfWlanInfo::ExternalizeL(RWriteStream& aStream) const
       
   155 	{
       
   156 	aStream << iSsid;
       
   157 	aStream.WriteInt16L( iStrengthLevel );
       
   158 	aStream.WriteInt32L( iSecurityMode );
       
   159 	aStream.WriteInt8L( iVisibility );
       
   160 	aStream.WriteInt32L( iNetMode );
       
   161 	aStream.WriteInt32L( iIapId );
       
   162 	aStream.WriteInt8L( iCoverage );
       
   163 	aStream.WriteInt32L( iTransferRate );
       
   164 	aStream.WriteInt8L( iConnectionState );
       
   165 	aStream.WriteInt8L( iFilterFlags );
       
   166 	aStream.WriteInt8L( iBrandId );
       
   167 	aStream.WriteInt8L( iPriority );
       
   168 	aStream << iNetworkName;
       
   169 	aStream << iRawSsid;
       
   170 	}
       
   171 
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // TWsfWlanInfo::SignalStrength
       
   175 // ---------------------------------------------------------------------------
       
   176 //    
       
   177 EXPORT_C TWsfWlanSignalStrengthLevel TWsfWlanInfo::SignalStrength()
       
   178 	{
       
   179 	// check the absolute signal level and return symbolic representation
       
   180 	// smaller value means stronger signal
       
   181 	TWsfWlanSignalStrengthLevel level( EAverage );
       
   182 	
       
   183     if ( iStrengthLevel < EWlanSignalStrengthGood )
       
   184         {
       
   185         level = EExcelent;
       
   186         }
       
   187     else if ( iStrengthLevel > EWlanSignalStrengthLow )
       
   188         {
       
   189         if ( iStrengthLevel == EWlanSignalUnavailable )
       
   190             {
       
   191             level = ENoSignal;
       
   192             }
       
   193         else
       
   194             {
       
   195             level = EPoor;
       
   196             }
       
   197         }
       
   198 
       
   199     return level;
       
   200 	}
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // TWsfWlanInfo::SignalStrengthPercentage
       
   205 // ---------------------------------------------------------------------------
       
   206 //    
       
   207 EXPORT_C TInt TWsfWlanInfo::SignalStrengthPercentage()
       
   208 	{
       
   209 	// smaller value means stronger signal
       
   210 	TInt signalStrength( 0 );
       
   211 	
       
   212     if ( iStrengthLevel <= EWlanSignalStrengthMax )
       
   213         {
       
   214         signalStrength = KMaxPercentage;
       
   215         }
       
   216     else if ( iStrengthLevel < EWlanSignalStrengthMin )
       
   217         {
       
   218         TInt diff = EWlanSignalStrengthMin - iStrengthLevel;
       
   219         signalStrength = diff * KMaxPercentage / 
       
   220                            ( EWlanSignalStrengthMin - EWlanSignalStrengthMax );
       
   221         }
       
   222         
       
   223     return signalStrength;
       
   224 	}
       
   225 
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // TWsfWlanInfo::GetSsidAsUnicodeLC
       
   229 // ---------------------------------------------------------------------------
       
   230 //    
       
   231 EXPORT_C HBufC* TWsfWlanInfo::GetIapNameAsUnicodeLC()
       
   232     {
       
   233     // This is essentially the same as ssid conversion
       
   234     return GetSsidAsUnicodeLC( iNetworkName );
       
   235     }
       
   236 
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // TWsfWlanInfo::GetSsidAsUtf8LC
       
   240 // ---------------------------------------------------------------------------
       
   241 //    
       
   242 EXPORT_C HBufC8* TWsfWlanInfo::GetIapNameAsUtf8LC()
       
   243     {
       
   244     HBufC8* networkName = iNetworkName.AllocLC();
       
   245     return networkName;
       
   246     }
       
   247 
       
   248 
       
   249 // End of file
       
   250