sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: //#include sl@0: //#include sl@0: //#include sl@0: sl@0: #include sl@0: sl@0: GLDEF_D RTest gTest(_L("macset utility")); sl@0: //GLDEF_D RFs gFs; sl@0: GLDEF_D RBusDevEthernet card; sl@0: sl@0: sl@0: #define PDD_NAME _L("Ethernet") sl@0: #define LDD_NAME _L("Enet") sl@0: sl@0: LOCAL_C void ReadMac() sl@0: // sl@0: // Read and display the current config sl@0: // sl@0: { sl@0: TBuf8<32> config; sl@0: sl@0: // MAC Address starts at the 4th byte sl@0: config.SetMax(); sl@0: card.Config(config); sl@0: sl@0: // gTest.Printf(_L("Ethernet Status :")); sl@0: // if (config[0] == KEthCardReady) sl@0: // gTest.Printf(_L(" Ready\n")); sl@0: // else sl@0: // gTest.Printf(_L(" NOT Ready\n")); sl@0: sl@0: gTest.Printf(_L("Ethernet Speed :")); sl@0: switch (config[0]) sl@0: { sl@0: case KEthSpeedUnknown: sl@0: gTest.Printf(_L(" Unknown\n")); sl@0: break; sl@0: case KEthSpeedAuto: sl@0: gTest.Printf(_L(" Auto\n")); sl@0: break; sl@0: case KEthSpeed10BaseT: sl@0: gTest.Printf(_L(" 10 MBit\n")); sl@0: break; sl@0: case KEthSpeed100BaseTX: sl@0: gTest.Printf(_L(" 100 MBit\n")); sl@0: break; sl@0: default: sl@0: gTest.Printf(_L(" ERROR\n")); sl@0: } sl@0: sl@0: gTest.Printf(_L("Duplex Setting :")); sl@0: switch (config[1]) sl@0: { sl@0: case KEthDuplexUnknown: sl@0: gTest.Printf(_L(" Unknown\n")); sl@0: break; sl@0: case KEthDuplexAuto: sl@0: gTest.Printf(_L(" Auto\n")); sl@0: break; sl@0: case KEthDuplexFull: sl@0: gTest.Printf(_L(" Full\n")); sl@0: break; sl@0: case KEthDuplexHalf: sl@0: gTest.Printf(_L(" Half\n")); sl@0: break; sl@0: default: sl@0: gTest.Printf(_L(" ERROR\n")); sl@0: } sl@0: sl@0: gTest.Printf(_L("MAC :")); sl@0: gTest.Printf(_L(" %2x:%2x:%2x:%2x:%2x:%2x\n\n"), sl@0: config[2], config[3], sl@0: config[4], config[5], sl@0: config[6], config[7]); sl@0: } sl@0: sl@0: LOCAL_C void WriteMac() sl@0: // sl@0: // Write the new mac address to the card sl@0: // sl@0: { sl@0: TBuf8<8> ioctlBuf; sl@0: // TEthernetConfigV01 newInfo; sl@0: sl@0: // TRequestStatus status; sl@0: TBuf<20> validChars(_L("0123456789abcdef")); sl@0: TUint8 value; sl@0: TUint8 upper=0; sl@0: TChar c; sl@0: TInt pos; sl@0: TBool bResult = ETrue; sl@0: sl@0: TBuf8<32> config; sl@0: sl@0: // Obtain command line parameters sl@0: // TPtrC option; sl@0: sl@0: // CCommandLineArguments* args = CCommandLineArguments::NewLC(); sl@0: TBuf<256> cmd; sl@0: User::CommandLine(cmd); sl@0: sl@0: // MAC Address starts at the 4th byte sl@0: config.SetMax(); sl@0: card.Config(config); sl@0: sl@0: gTest.Printf(_L("Command length is %d\n"), cmd.Length()); sl@0: sl@0: if (cmd.Length()>0) sl@0: // if (args->Count() > 2) sl@0: { sl@0: // option.Set(args->Arg(1)); sl@0: if(cmd[0]=='-' && (cmd[1]=='s' || cmd[1]=='S')) sl@0: // if(!option.CompareF(_L("-S"))) sl@0: { sl@0: ioctlBuf.SetLength(8); sl@0: ioctlBuf[0] = KEthSpeed10BaseT; sl@0: // newInfo.iEthSpeed = KEthSpeed10BaseT; sl@0: ioctlBuf[1] = KEthDuplexHalf; sl@0: // newInfo.iEthDuplex = KEthDuplexHalf; sl@0: sl@0: for(int i = 0; i<6; i++) sl@0: { sl@0: c = cmd[3+(i*2)]; sl@0: // c = args->Arg(2)[2*i]; sl@0: c.LowerCase(); sl@0: if((pos = validChars.Locate(c))==KErrNotFound) sl@0: { sl@0: pos = upper; sl@0: break; sl@0: } sl@0: upper = (TUint8)pos; sl@0: c = cmd[4+(i*2)]; sl@0: // c = args->Arg(2)[(2*i)+1]; sl@0: c.LowerCase(); sl@0: if((pos = validChars.Locate(c))==KErrNotFound) sl@0: { sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: value = (TUint8)pos; sl@0: value = (TUint8)((upper<<4) | value); sl@0: sl@0: ioctlBuf[i+2] = value; sl@0: // newInfo.iEthAddress[i] = value; sl@0: } sl@0: sl@0: gTest.Printf(_L("\nSetting MAC to %2x:%2x:%2x:%2x:%2x:%2x\n"), sl@0: ioctlBuf[2], ioctlBuf[3], sl@0: ioctlBuf[4], ioctlBuf[5], sl@0: ioctlBuf[6], ioctlBuf[7]); sl@0: sl@0: card.SetMAC(ioctlBuf); sl@0: // card.IOControl(status,ioctlBuf); sl@0: gTest.Printf(_L("Done\n")); sl@0: } sl@0: else if(cmd[0]=='-' && (cmd[1]=='c' || cmd[1]=='C')) sl@0: { sl@0: sl@0: for(int i = 0; i<6; i++) sl@0: { sl@0: c = cmd[3+(i*2)]; sl@0: c.LowerCase(); sl@0: if((pos = validChars.Locate(c))==KErrNotFound) sl@0: { sl@0: pos = upper; sl@0: bResult = EFalse; sl@0: break; sl@0: } sl@0: upper = (TUint8)pos; sl@0: c = cmd[4+(i*2)]; sl@0: sl@0: c.LowerCase(); sl@0: if((pos = validChars.Locate(c))==KErrNotFound) sl@0: { sl@0: //User::Leave(KErrNotFound); sl@0: bResult = EFalse; sl@0: break; sl@0: } sl@0: value = (TUint8)pos; sl@0: value = (TUint8)((upper<<4) | value); sl@0: sl@0: if( config[i+2] != value) sl@0: { sl@0: bResult = EFalse; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if( EFalse == bResult ) sl@0: gTest.Printf(_L("Test FAILED\n\n")); sl@0: else sl@0: gTest.Printf(_L("Test PASSED\n\n")); sl@0: sl@0: } sl@0: else sl@0: { sl@0: gTest.Printf(_L("Invalid option")); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: gTest.Printf(_L("Call with -s to set new MAC\n")); sl@0: gTest.Printf(_L(" eg. macset -s 102030405060\n")); sl@0: sl@0: gTest.Printf(_L("\nCall with -c to test MAC value\n")); sl@0: gTest.Printf(_L(" eg. macset -c 00aabbccddee to check if MAC == 00aabbccddee\n")); sl@0: } sl@0: sl@0: // CleanupStack::PopAndDestroy( /* args */ ); sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt InitGlobals() sl@0: // sl@0: // Initialise global variables. sl@0: // sl@0: { sl@0: TInt err; sl@0: TBuf8<8> ioctlBuf; sl@0: // TRequestStatus status; sl@0: sl@0: gTest.Printf(_L("**Load LDD\n")); sl@0: err=User::LoadLogicalDevice(LDD_NAME); sl@0: if (err!=KErrNone && err!=KErrAlreadyExists) sl@0: return(err); sl@0: sl@0: gTest.Printf(_L("**Load PDD\n")); sl@0: err=User::LoadPhysicalDevice(PDD_NAME); sl@0: if (err!=KErrNone && err!=KErrAlreadyExists) sl@0: return(err); sl@0: sl@0: gTest.Printf(_L("**Open device\n")); sl@0: User::LeaveIfError(card.Open(0)); sl@0: // User::LeaveIfError(card.Open(card.VersionRequired(),0,NULL)); sl@0: // ioctlBuf.SetLength(1); sl@0: // ioctlBuf[0] = RBusDevEthernet::EControlCaps; sl@0: gTest.Printf(_L("**Getconfig\n")); sl@0: sl@0: card.Caps(ioctlBuf); sl@0: // card.IOControl(status,ioctlBuf); sl@0: // if(ioctlBuf[0] != KEventPCCardReady) sl@0: // { sl@0: // card.Close(); sl@0: // User::Leave(KErrNotReady); sl@0: // } sl@0: gTest.Printf(_L("**Init Done\n")); sl@0: return KErrNone; sl@0: } sl@0: sl@0: LOCAL_C void DestroyGlobals() sl@0: // sl@0: // Free global variables sl@0: // sl@0: { sl@0: gTest.Printf(_L("**Free PDD\n")); sl@0: User::FreePhysicalDevice(PDD_NAME); sl@0: gTest.Printf(_L("**Free LDD\n")); sl@0: User::FreeLogicalDevice(LDD_NAME); sl@0: sl@0: sl@0: // gFs.Close(); sl@0: } sl@0: sl@0: LOCAL_C void RunMacSetL() sl@0: // sl@0: // Run all the tests sl@0: // sl@0: { sl@0: sl@0: TInt ret = InitGlobals(); sl@0: if(ret != KErrNone) sl@0: return; sl@0: sl@0: ReadMac(); sl@0: WriteMac(); sl@0: DestroyGlobals(); sl@0: } sl@0: sl@0: EXPORT_C TInt E32Main() sl@0: // sl@0: // Main sl@0: // sl@0: { sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: CActiveScheduler* theActiveScheduler = new CActiveScheduler(); sl@0: CActiveScheduler::Install(theActiveScheduler); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TRAPD(err,RunMacSetL()); sl@0: if (err!=KErrNone) sl@0: gTest.Printf(_L("ERROR: Leave %d\n"),err); sl@0: sl@0: gTest.Printf(_L("Press any key ...\n")); sl@0: gTest.Getch(); sl@0: gTest.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: delete cleanup; sl@0: delete theActiveScheduler; sl@0: return KErrNone; sl@0: }