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