wlanutilities/wlansniffer/wlaninfo/src/wsfwlaninfo.cpp
changeset 19 10810c91db26
parent 3 ff3b37722600
child 22 498f36116140
equal deleted inserted replaced
3:ff3b37722600 19:10810c91db26
     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 	aStream >> iRawSsid;
       
   145 	}
       
   146 
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // TWsfWlanInfo::ExternalizeL
       
   150 // ---------------------------------------------------------------------------
       
   151 //    
       
   152 EXPORT_C void TWsfWlanInfo::ExternalizeL(RWriteStream& aStream) const
       
   153 	{
       
   154 	aStream << iSsid;
       
   155 	aStream.WriteInt16L( iStrengthLevel );
       
   156 	aStream.WriteInt32L( iSecurityMode );
       
   157 	aStream.WriteInt8L( iVisibility );
       
   158 	aStream.WriteInt32L( iNetMode );
       
   159 	aStream.WriteInt32L( iIapId );
       
   160 	aStream.WriteInt8L( iCoverage );
       
   161 	aStream.WriteInt32L( iTransferRate );
       
   162 	aStream.WriteInt8L( iConnectionState );
       
   163 	aStream.WriteInt8L( iFilterFlags );
       
   164 	aStream.WriteInt8L( iBrandId );
       
   165 	aStream.WriteInt8L( iPriority );
       
   166 	aStream << iNetworkName;
       
   167 	aStream << iRawSsid;
       
   168 	}
       
   169 
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // TWsfWlanInfo::SignalStrength
       
   173 // ---------------------------------------------------------------------------
       
   174 //    
       
   175 EXPORT_C TWsfWlanSignalStrengthLevel TWsfWlanInfo::SignalStrength()
       
   176 	{
       
   177 	// check the absolute signal level and return symbolic representation
       
   178 	// smaller value means stronger signal
       
   179 	TWsfWlanSignalStrengthLevel level( EAverage );
       
   180 	
       
   181     if ( iStrengthLevel < EWlanSignalStrengthGood )
       
   182         {
       
   183         level = EExcelent;
       
   184         }
       
   185     else if ( iStrengthLevel > EWlanSignalStrengthLow )
       
   186         {
       
   187         if ( iStrengthLevel == EWlanSignalUnavailable )
       
   188             {
       
   189             level = ENoSignal;
       
   190             }
       
   191         else
       
   192             {
       
   193             level = EPoor;
       
   194             }
       
   195         }
       
   196 
       
   197     return level;
       
   198 	}
       
   199 
       
   200 
       
   201 // ---------------------------------------------------------------------------
       
   202 // TWsfWlanInfo::SignalStrengthPercentage
       
   203 // ---------------------------------------------------------------------------
       
   204 //    
       
   205 EXPORT_C TInt TWsfWlanInfo::SignalStrengthPercentage()
       
   206 	{
       
   207 	// smaller value means stronger signal
       
   208 	TInt signalStrength( 0 );
       
   209 	
       
   210     if ( iStrengthLevel <= EWlanSignalStrengthMax )
       
   211         {
       
   212         signalStrength = KMaxPercentage;
       
   213         }
       
   214     else if ( iStrengthLevel < EWlanSignalStrengthMin )
       
   215         {
       
   216         TInt diff = EWlanSignalStrengthMin - iStrengthLevel;
       
   217         signalStrength = diff * KMaxPercentage / 
       
   218                            ( EWlanSignalStrengthMin - EWlanSignalStrengthMax );
       
   219         }
       
   220         
       
   221     return signalStrength;
       
   222 	}
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // TWsfWlanInfo::GetSsidAsUnicodeLC
       
   227 // ---------------------------------------------------------------------------
       
   228 //    
       
   229 EXPORT_C HBufC* TWsfWlanInfo::GetIapNameAsUnicodeLC()
       
   230     {
       
   231     // This is essentially the same as ssid conversion
       
   232     return GetSsidAsUnicodeLC( iNetworkName );
       
   233     }
       
   234 
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // TWsfWlanInfo::GetSsidAsUtf8LC
       
   238 // ---------------------------------------------------------------------------
       
   239 //    
       
   240 EXPORT_C HBufC8* TWsfWlanInfo::GetIapNameAsUtf8LC()
       
   241     {
       
   242     HBufC8* networkName = iNetworkName.AllocLC();
       
   243     return networkName;
       
   244     }
       
   245 
       
   246 
       
   247 // End of file
       
   248