Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 //#include <s32file.h>
19 //#include <c32comm.h>
20 //#include <bacline.h>
22 #include <d32ethernet.h>
24 GLDEF_D RTest gTest(_L("macset utility"));
26 GLDEF_D RBusDevEthernet card;
29 #define PDD_NAME _L("Ethernet")
30 #define LDD_NAME _L("Enet")
32 LOCAL_C void ReadMac()
34 // Read and display the current config
39 // MAC Address starts at the 4th byte
43 // gTest.Printf(_L("Ethernet Status :"));
44 // if (config[0] == KEthCardReady)
45 // gTest.Printf(_L(" Ready\n"));
47 // gTest.Printf(_L(" NOT Ready\n"));
49 gTest.Printf(_L("Ethernet Speed :"));
52 case KEthSpeedUnknown:
53 gTest.Printf(_L(" Unknown\n"));
56 gTest.Printf(_L(" Auto\n"));
58 case KEthSpeed10BaseT:
59 gTest.Printf(_L(" 10 MBit\n"));
61 case KEthSpeed100BaseTX:
62 gTest.Printf(_L(" 100 MBit\n"));
65 gTest.Printf(_L(" ERROR\n"));
68 gTest.Printf(_L("Duplex Setting :"));
71 case KEthDuplexUnknown:
72 gTest.Printf(_L(" Unknown\n"));
75 gTest.Printf(_L(" Auto\n"));
78 gTest.Printf(_L(" Full\n"));
81 gTest.Printf(_L(" Half\n"));
84 gTest.Printf(_L(" ERROR\n"));
87 gTest.Printf(_L("MAC :"));
88 gTest.Printf(_L(" %2x:%2x:%2x:%2x:%2x:%2x\n\n"),
91 config[6], config[7]);
94 LOCAL_C void WriteMac()
96 // Write the new mac address to the card
100 // TEthernetConfigV01 newInfo;
102 // TRequestStatus status;
103 TBuf<20> validChars(_L("0123456789abcdef"));
108 TBool bResult = ETrue;
112 // Obtain command line parameters
115 // CCommandLineArguments* args = CCommandLineArguments::NewLC();
117 User::CommandLine(cmd);
119 // MAC Address starts at the 4th byte
123 gTest.Printf(_L("Command length is %d\n"), cmd.Length());
126 // if (args->Count() > 2)
128 // option.Set(args->Arg(1));
129 if(cmd[0]=='-' && (cmd[1]=='s' || cmd[1]=='S'))
130 // if(!option.CompareF(_L("-S")))
132 ioctlBuf.SetLength(8);
133 ioctlBuf[0] = KEthSpeed10BaseT;
134 // newInfo.iEthSpeed = KEthSpeed10BaseT;
135 ioctlBuf[1] = KEthDuplexHalf;
136 // newInfo.iEthDuplex = KEthDuplexHalf;
138 for(int i = 0; i<6; i++)
141 // c = args->Arg(2)[2*i];
143 if((pos = validChars.Locate(c))==KErrNotFound)
150 // c = args->Arg(2)[(2*i)+1];
152 if((pos = validChars.Locate(c))==KErrNotFound)
154 User::Leave(KErrNotFound);
157 value = (TUint8)((upper<<4) | value);
159 ioctlBuf[i+2] = value;
160 // newInfo.iEthAddress[i] = value;
163 gTest.Printf(_L("\nSetting MAC to %2x:%2x:%2x:%2x:%2x:%2x\n"),
164 ioctlBuf[2], ioctlBuf[3],
165 ioctlBuf[4], ioctlBuf[5],
166 ioctlBuf[6], ioctlBuf[7]);
168 card.SetMAC(ioctlBuf);
169 // card.IOControl(status,ioctlBuf);
170 gTest.Printf(_L("Done\n"));
172 else if(cmd[0]=='-' && (cmd[1]=='c' || cmd[1]=='C'))
175 for(int i = 0; i<6; i++)
179 if((pos = validChars.Locate(c))==KErrNotFound)
189 if((pos = validChars.Locate(c))==KErrNotFound)
191 //User::Leave(KErrNotFound);
196 value = (TUint8)((upper<<4) | value);
198 if( config[i+2] != value)
205 if( EFalse == bResult )
206 gTest.Printf(_L("Test FAILED\n\n"));
208 gTest.Printf(_L("Test PASSED\n\n"));
213 gTest.Printf(_L("Invalid option"));
218 gTest.Printf(_L("Call with -s to set new MAC\n"));
219 gTest.Printf(_L(" eg. macset -s 102030405060\n"));
221 gTest.Printf(_L("\nCall with -c to test MAC value\n"));
222 gTest.Printf(_L(" eg. macset -c 00aabbccddee to check if MAC == 00aabbccddee\n"));
225 // CleanupStack::PopAndDestroy( /* args */ );
229 LOCAL_C TInt InitGlobals()
231 // Initialise global variables.
236 // TRequestStatus status;
238 gTest.Printf(_L("**Load LDD\n"));
239 err=User::LoadLogicalDevice(LDD_NAME);
240 if (err!=KErrNone && err!=KErrAlreadyExists)
243 gTest.Printf(_L("**Load PDD\n"));
244 err=User::LoadPhysicalDevice(PDD_NAME);
245 if (err!=KErrNone && err!=KErrAlreadyExists)
248 gTest.Printf(_L("**Open device\n"));
249 User::LeaveIfError(card.Open(0));
250 // User::LeaveIfError(card.Open(card.VersionRequired(),0,NULL));
251 // ioctlBuf.SetLength(1);
252 // ioctlBuf[0] = RBusDevEthernet::EControlCaps;
253 gTest.Printf(_L("**Getconfig\n"));
256 // card.IOControl(status,ioctlBuf);
257 // if(ioctlBuf[0] != KEventPCCardReady)
260 // User::Leave(KErrNotReady);
262 gTest.Printf(_L("**Init Done\n"));
266 LOCAL_C void DestroyGlobals()
268 // Free global variables
271 gTest.Printf(_L("**Free PDD\n"));
272 User::FreePhysicalDevice(PDD_NAME);
273 gTest.Printf(_L("**Free LDD\n"));
274 User::FreeLogicalDevice(LDD_NAME);
280 LOCAL_C void RunMacSetL()
286 TInt ret = InitGlobals();
295 EXPORT_C TInt E32Main()
300 CTrapCleanup* cleanup = CTrapCleanup::New();
301 CActiveScheduler* theActiveScheduler = new CActiveScheduler();
302 CActiveScheduler::Install(theActiveScheduler);
306 TRAPD(err,RunMacSetL());
308 gTest.Printf(_L("ERROR: Leave %d\n"),err);
310 gTest.Printf(_L("Press any key ...\n"));
317 delete theActiveScheduler;