commands/sysinfo/sysinfo.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // sysinfo.cpp
       
     2 // 
       
     3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 //
       
    14 // CCmdSysInfo.
       
    15 //
       
    16 #include "u32std.h"
       
    17 #include <ETELMM.H>
       
    18 #include "sysinfo.h"
       
    19 #include <fshell/common.mmh>
       
    20 #include <fshell/ltkhal.h>
       
    21 #include <fshell/ltkutils.h>
       
    22 #ifdef FSHELL_CORE_SUPPORT_SYSINFO_WLAN
       
    23 #include <wlansdkpskeys.h>	//for WLAN info
       
    24 #endif
       
    25 #include <e32rom.h>
       
    26 
       
    27 	
       
    28 CCommandBase* CCmdSysInfo::NewLC()
       
    29 	{
       
    30 	CCmdSysInfo* self = new (ELeave) CCmdSysInfo();
       
    31 	CleanupStack::PushL(self);
       
    32 	self->BaseConstructL();
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CCmdSysInfo::~CCmdSysInfo()
       
    37 	{
       
    38 	}
       
    39 
       
    40 CCmdSysInfo::CCmdSysInfo()
       
    41 	: CCommandBase(EReportAllErrors)
       
    42 	{
       
    43 	}
       
    44 
       
    45 void CCmdSysInfo::PrintHalL(HALData::TAttribute aHalAttribute)
       
    46 	{
       
    47 	LtkUtils::CHalAttribute* attrib = LtkUtils::GetHalInfoL(aHalAttribute);
       
    48 	if (attrib->iError)
       
    49 		{
       
    50 		PrintWarning(_L("Unable to read %S: %S (%d)"), &attrib->iAttributeName, Stringify::Error(attrib->iError), attrib->iError);
       
    51 		}
       
    52 	else
       
    53 		{
       
    54 		Printf(_L("%S: %S\r\n"), &attrib->iAttributeName, attrib->iDescription);
       
    55 		}
       
    56 	delete attrib;
       
    57 	}
       
    58 
       
    59 void CCmdSysInfo::PrintWlanL()
       
    60 	{
       
    61 #ifdef FSHELL_CORE_SUPPORT_SYSINFO_WLAN
       
    62     //result format 00:18:0f:1e:96:a2.
       
    63     TBuf8<KPSWlanMacAddressLength> DesC8AddrText;
       
    64     TBuf<50> formatedMacAddress;
       
    65     LeaveIfErr(RProperty::Get(KPSUidWlan,KPSWlanMacAddress,DesC8AddrText), _L("Unable to get MAC address"));
       
    66     for ( TInt i=0; i < (TInt)KPSWlanMacAddressLength; i++ )
       
    67         {
       
    68         // Set separator
       
    69         if( i > 0 )
       
    70             formatedMacAddress.Append(':');
       
    71  
       
    72         // Set data
       
    73         TBuf<10> FormatText;
       
    74         FormatText.Format(_L("%02x"), DesC8AddrText[i]);
       
    75         formatedMacAddress.Append(FormatText);
       
    76         }
       
    77     Printf(_L("WLAN MAC Address: %S\r\n"), &formatedMacAddress);
       
    78 #endif
       
    79 	}
       
    80 
       
    81 void CCmdSysInfo::PrintPhoneIdL()
       
    82 	{
       
    83 #ifdef FSHELL_TELEPHONY_SUPPORT
       
    84 	TRequestStatus status;
       
    85 
       
    86 	RTelServer telSvr;
       
    87 	LeaveIfErr(telSvr.Connect(), _L("Unable to connect to telephony server"));
       
    88 	CleanupClosePushL(telSvr);
       
    89 
       
    90 	RMobilePhone mobilePhone;
       
    91 	LeaveIfErr(mobilePhone.Open(telSvr, _L("DefaultPhone")), _L("Unable to open default mobile phone"));
       
    92 	CleanupClosePushL(mobilePhone);
       
    93 		
       
    94 	TUint32 identCap;
       
    95 	mobilePhone.GetIdentityCaps(identCap);
       
    96 		
       
    97 	RMobilePhone::TMobilePhoneIdentityV1 Id;
       
    98 	mobilePhone.GetPhoneId(status, Id);
       
    99 	User::WaitForRequest(status);
       
   100 
       
   101 	LeaveIfErr(status.Int(), _L("Unable to retrieve phone identity"));
       
   102 	if (identCap & RMobilePhone::KCapsGetManufacturer)
       
   103 		Printf(_L("Manufacturer (from TSY): %S\r\n"), &(Id.iManufacturer) );
       
   104 
       
   105 	if (identCap & RMobilePhone::KCapsGetModel)
       
   106 		Printf(_L("Model (from TSY): %S\r\n"), &(Id.iModel) );
       
   107 		
       
   108 	if (identCap & RMobilePhone::KCapsGetRevision)
       
   109 		Printf(_L("Revision (from TSY): %S\r\n"), &(Id.iRevision) );
       
   110 		
       
   111 	if (identCap & RMobilePhone::KCapsGetSerialNumber)
       
   112 		Printf(_L("SerialNumber (IMEI): %S\r\n"), &(Id.iSerialNumber) );
       
   113 	
       
   114 	//query subscriber id
       
   115 	if (identCap & RMobilePhone::KCapsGetSubscriberId)
       
   116 		{
       
   117 		RMobilePhone::TMobilePhoneSubscriberId subsId;
       
   118 		mobilePhone.GetSubscriberId(status, subsId);
       
   119 		User::WaitForRequest(status);
       
   120 
       
   121 		LeaveIfErr(status.Int(), _L("Unable to query subscriber id"));
       
   122 		Printf(_L("SubscriberId (IMSI): %S\r\n"), &(subsId) );
       
   123 		}
       
   124 
       
   125 	TPckgBuf<RMobilePhone::TMobilePhoneNetworkInfoV1> info;
       
   126 	RMobilePhone::TMobilePhoneLocationAreaV1 loc;
       
   127 	mobilePhone.GetCurrentNetwork(status, info, loc);
       
   128 	User::WaitForRequest(status);
       
   129 	LeaveIfErr(status.Int(), _L("Unable to get current network info"));
       
   130 	Printf(_L8("Network id: %S "), &info().iNetworkId);
       
   131 	Printf(_L("shortName: %S longName: %S displayTag: %S"), &info().iShortName, &info().iLongName, &info().iDisplayTag);
       
   132 
       
   133 	CleanupStack::PopAndDestroy();	//mobilePhone
       
   134 	CleanupStack::PopAndDestroy();	//telSvr
       
   135 #endif	
       
   136 	}	
       
   137 
       
   138 void CCmdSysInfo::DoRunL()
       
   139 	{
       
   140 	if (iMachineUIDOnly)
       
   141 		{
       
   142 		// sysinfo command-line configured to return only the machine uid value & nothing else
       
   143 		TInt value;
       
   144 		TInt err = HAL::Get(HALData::EMachineUid, value);
       
   145 		if (err)
       
   146 			{
       
   147 			PrintWarning(_L("Unable to read Machine UID %S (%d)"), Stringify::Error(err), err);
       
   148 			}
       
   149 		else
       
   150 			{
       
   151 			TBuf<10> buf;
       
   152 			buf.Format(_L("%d"), value);
       
   153 			Write(buf);
       
   154 			}
       
   155 		}
       
   156 	else
       
   157 		{
       
   158 		// sys info command-line configured to return all information, including HAL field description
       
   159 		PrintHalL(HALData::EManufacturer);
       
   160 		PrintHalL(HALData::EManufacturerHardwareRev);
       
   161 		PrintHalL(HALData::EManufacturerSoftwareRev);
       
   162 		PrintHalL(HALData::EManufacturerSoftwareBuild);
       
   163 		PrintHalL(HALData::EModel);
       
   164 		PrintHalL(HALData::EMachineUid);
       
   165 		PrintHalL(HALData::ECPUSpeed);
       
   166 		PrintHalL(HALData::ESystemStartupReason);
       
   167 		PrintHalL(HALData::ESystemTickPeriod);
       
   168 		PrintHalL(HALData::ENanoTickPeriod);
       
   169 		PrintHalL(HALData::EFastCounterFrequency);
       
   170 		PrintHalL(HALData::EFastCounterCountsUp);
       
   171 		PrintHalL(HALData::ESystemException);
       
   172 		PrintHalL(HALData::EDisplayXPixels);
       
   173 		PrintHalL(HALData::EDisplayYPixels);
       
   174 		PrintHalL(HALData::EDisplayXTwips);
       
   175 		PrintHalL(HALData::EDisplayYTwips);
       
   176 		PrintHalL(HALData::EDisplayColors);
       
   177 		PrintKernelHalStuff();
       
   178 		PrintRomVersion();
       
   179 		TRAP_IGNORE(PrintWlanL());
       
   180 		TRAP_IGNORE(PrintPhoneIdL());
       
   181 		}
       
   182 	}
       
   183 	
       
   184 const TDesC& CCmdSysInfo::Name() const
       
   185 	{
       
   186 	_LIT(KName, "sysinfo");
       
   187 	return KName;
       
   188 	}
       
   189 
       
   190 void CCmdSysInfo::OptionsL(RCommandOptionList& aOptions)
       
   191 	{
       
   192 	_LIT(KOptUid, "machine-uid");
       
   193 	aOptions.AppendBoolL(iMachineUIDOnly, KOptUid);
       
   194 	}
       
   195 
       
   196 EXE_BOILER_PLATE(CCmdSysInfo)
       
   197 
       
   198 void CCmdSysInfo::PrintKernelHalStuff()
       
   199 	{
       
   200 	enum TKernelConfigFlagsNotIn91
       
   201 		{
       
   202 		EKernelConfigPlatSecLocked = 1<<7,
       
   203 		EKernelConfigCrazyScheduling = 1<<8,
       
   204 
       
   205 		EKernelConfigPagingPolicyNoPaging = 0,
       
   206 		EKernelConfigPagingPolicyAlwaysPage = 1,
       
   207 		EKernelConfigPagingPolicyDefaultUnpaged = 2,
       
   208 		EKernelConfigPagingPolicyDefaultPaged = 3,
       
   209 
       
   210 		EKernelConfigCodePagingPolicyShift			= 5,
       
   211 		EKernelConfigCodePagingPolicyMask			= 3<<5,
       
   212 		EKernelConfigCodePagingPolicyNoPaging		= EKernelConfigPagingPolicyNoPaging<<5,
       
   213 		EKernelConfigCodePagingPolicyAlwaysPage		= EKernelConfigPagingPolicyAlwaysPage<<5,
       
   214 		EKernelConfigCodePagingPolicyDefaultUnpaged	= EKernelConfigPagingPolicyDefaultUnpaged<<5,
       
   215 		EKernelConfigCodePagingPolicyDefaultPaged	= EKernelConfigPagingPolicyDefaultPaged<<5,
       
   216 
       
   217 		EKernelConfigDataPagingPolicyShift			= 9,
       
   218 		EKernelConfigDataPagingPolicyMask			= 3<<9,
       
   219 		};
       
   220 
       
   221 	enum THalFunctionsNotIn91
       
   222 		{
       
   223 		EKernelHalSmpSupported = 15,
       
   224 		EKernelHalNumLogicalCpus = 16,
       
   225 		EKernelHalConfigFlags = 20,
       
   226 		};
       
   227 
       
   228 	// Memory model
       
   229 	TUint memModelInfo = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, 0, 0);
       
   230 	Printf(_L("Memory model: "));
       
   231 	const TInt EMemModelTypeFlexible = 4;
       
   232 	switch (memModelInfo & EMemModelTypeMask)
       
   233 		{
       
   234 		case EMemModelTypeDirect:
       
   235 			Printf(_L("Direct")); break;
       
   236 		case EMemModelTypeMoving:
       
   237 			Printf(_L("Moving")); break;
       
   238 		case EMemModelTypeMultiple:
       
   239 			Printf(_L("Multiple")); break;
       
   240 		case EMemModelTypeEmul:
       
   241 			Printf(_L("Emulator")); break;
       
   242 		case EMemModelTypeFlexible:
       
   243 			Printf(_L("Flexible")); break;
       
   244 		default:
       
   245 			Printf(_L("Unknown (%d)"), memModelInfo & EMemModelTypeMask);
       
   246 			break;
       
   247 		}
       
   248 	Printf(_L("\r\n"));
       
   249 
       
   250 	// Hal config
       
   251 	TInt flags = UserSvr::HalFunction(EHalGroupKernel, EKernelHalConfigFlags, 0, 0); // Not the most documented of APIs but has been around since at least v9.1
       
   252 	if (flags < 0)
       
   253 		{
       
   254 #ifdef __EPOC32__
       
   255 		// The only things that are dynamically calculated are things that aren't supported on platforms that don't support the HalFunction, so this is a good compromise
       
   256 		flags = ((const TRomHeader*)UserSvr::RomHeaderAddress())->iKernelConfigFlags;
       
   257 #else
       
   258 		return;
       
   259 #endif
       
   260 		}
       
   261 
       
   262 	_LIT(KOn, "On");
       
   263 	_LIT(KOff, "Off");
       
   264 	Printf(_L("PlatSec Enforcement: %S\r\n"), (flags & EKernelConfigPlatSecEnforcement) ? &KOn : &KOff);
       
   265 	Printf(_L("PlatSec Locked: %S\r\n"), (flags & EKernelConfigPlatSecLocked) ? &KOn : &KOff);
       
   266 	Printf(_L("Crazy scheduling: %S\r\n"), (flags & EKernelConfigCrazyScheduling) ? &KOn : &KOff);
       
   267 
       
   268 	Printf(_L("Code paging: "));
       
   269 	PagingFormat((flags & EKernelConfigCodePagingPolicyMask) >> EKernelConfigCodePagingPolicyShift);
       
   270 	Printf(_L("\r\nData paging: "));
       
   271 	PagingFormat((flags & EKernelConfigDataPagingPolicyMask) >> EKernelConfigDataPagingPolicyShift);
       
   272 	Printf(_L("\r\n"));
       
   273 
       
   274 	// Num CPUs
       
   275 	TBool smpEnabled = (UserSvr::HalFunction(EHalGroupKernel, EKernelHalSmpSupported, 0, 0) == KErrNone);
       
   276 	if (smpEnabled)
       
   277 		{
       
   278 		TInt cpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
       
   279 		Printf(_L("Num CPUs: %d\r\n"), cpus);
       
   280 		}
       
   281 	else
       
   282 		{
       
   283 		Printf(_L("Num CPUs: 1 (no SMP)\r\n"));
       
   284 		}
       
   285 	}
       
   286 
       
   287 void CCmdSysInfo::PagingFormat(TUint aFlags)
       
   288 	{
       
   289 	enum TMoreFlagsNotIn91
       
   290 		{
       
   291 		EKernelConfigPagingPolicyNoPaging = 0,
       
   292 		EKernelConfigPagingPolicyAlwaysPage = 1,
       
   293 		EKernelConfigPagingPolicyDefaultUnpaged = 2,
       
   294 		EKernelConfigPagingPolicyDefaultPaged = 3,
       
   295 		};
       
   296 
       
   297 	switch (aFlags)
       
   298 		{
       
   299 		case EKernelConfigPagingPolicyNoPaging:
       
   300 			Printf(_L("No paging")); break;
       
   301 		case EKernelConfigPagingPolicyAlwaysPage:
       
   302 			Printf(_L("Always page")); break;
       
   303 		case EKernelConfigPagingPolicyDefaultUnpaged:
       
   304 			Printf(_L("Default unpaged")); break;
       
   305 		case EKernelConfigPagingPolicyDefaultPaged:
       
   306 			Printf(_L("Default paged")); break;
       
   307 		default:
       
   308 			break;
       
   309 		}
       
   310 	}
       
   311 
       
   312 typedef TInt(*TSysUtilGetSWVersionFunction)(TDes&);
       
   313 #ifdef __EPOC32__
       
   314 const TInt KSysUtilOrdinal = 9;
       
   315 #else
       
   316 const TInt KSysUtilOrdinal = 6;
       
   317 #endif
       
   318 
       
   319 void CCmdSysInfo::PrintRomVersion()
       
   320 	{
       
   321 #ifdef __EPOC32__
       
   322 	// Get checksum 
       
   323 	TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
       
   324 	if  (romHeader)
       
   325 		{
       
   326 		Printf(_L("Rom checksum: 0x%08x\r\n"), romHeader->iCheckSum);
       
   327 		}
       
   328 #endif
       
   329 
       
   330 	// Platform version
       
   331 	_LIT(KS60VersionDllName, "SysUtil.dll");
       
   332 	RLibrary lib;
       
   333 	if (lib.Load(KS60VersionDllName) == KErrNone)
       
   334 		{
       
   335 		// Get exported version function
       
   336 		TLibraryFunction fn = lib.Lookup(KSysUtilOrdinal);
       
   337 		if (fn != NULL)
       
   338 			{
       
   339 			TSysUtilGetSWVersionFunction sysUtilGetSWVersion = (TSysUtilGetSWVersionFunction) fn;
       
   340 			TBuf<128> buf;
       
   341 			TInt err = (*sysUtilGetSWVersion)(buf);
       
   342 			if (err)
       
   343 				{
       
   344 				Printf(_L("Error returned from SysUtilGetSWVersionFunction: %d\r\n"), err);
       
   345 				}
       
   346 			else
       
   347 				{
       
   348 				LtkUtils::ReplaceText(buf, _L("\n"), _L(" "));
       
   349 				Printf(_L("ROM version: %S\r\n"), &buf);
       
   350 				}
       
   351 			}
       
   352 		lib.Close();
       
   353 		}
       
   354 	}