0
|
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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <e32test.h>
|
|
17 |
#include <f32file.h>
|
|
18 |
//#include <s32file.h>
|
|
19 |
//#include <c32comm.h>
|
|
20 |
//#include <bacline.h>
|
|
21 |
|
|
22 |
#include <d32ethernet.h>
|
|
23 |
|
|
24 |
GLDEF_D RTest gTest(_L("macset utility"));
|
|
25 |
//GLDEF_D RFs gFs;
|
|
26 |
GLDEF_D RBusDevEthernet card;
|
|
27 |
|
|
28 |
|
|
29 |
#define PDD_NAME _L("Ethernet")
|
|
30 |
#define LDD_NAME _L("Enet")
|
|
31 |
|
|
32 |
LOCAL_C void ReadMac()
|
|
33 |
//
|
|
34 |
// Read and display the current config
|
|
35 |
//
|
|
36 |
{
|
|
37 |
TBuf8<32> config;
|
|
38 |
|
|
39 |
// MAC Address starts at the 4th byte
|
|
40 |
config.SetMax();
|
|
41 |
card.Config(config);
|
|
42 |
|
|
43 |
// gTest.Printf(_L("Ethernet Status :"));
|
|
44 |
// if (config[0] == KEthCardReady)
|
|
45 |
// gTest.Printf(_L(" Ready\n"));
|
|
46 |
// else
|
|
47 |
// gTest.Printf(_L(" NOT Ready\n"));
|
|
48 |
|
|
49 |
gTest.Printf(_L("Ethernet Speed :"));
|
|
50 |
switch (config[0])
|
|
51 |
{
|
|
52 |
case KEthSpeedUnknown:
|
|
53 |
gTest.Printf(_L(" Unknown\n"));
|
|
54 |
break;
|
|
55 |
case KEthSpeedAuto:
|
|
56 |
gTest.Printf(_L(" Auto\n"));
|
|
57 |
break;
|
|
58 |
case KEthSpeed10BaseT:
|
|
59 |
gTest.Printf(_L(" 10 MBit\n"));
|
|
60 |
break;
|
|
61 |
case KEthSpeed100BaseTX:
|
|
62 |
gTest.Printf(_L(" 100 MBit\n"));
|
|
63 |
break;
|
|
64 |
default:
|
|
65 |
gTest.Printf(_L(" ERROR\n"));
|
|
66 |
}
|
|
67 |
|
|
68 |
gTest.Printf(_L("Duplex Setting :"));
|
|
69 |
switch (config[1])
|
|
70 |
{
|
|
71 |
case KEthDuplexUnknown:
|
|
72 |
gTest.Printf(_L(" Unknown\n"));
|
|
73 |
break;
|
|
74 |
case KEthDuplexAuto:
|
|
75 |
gTest.Printf(_L(" Auto\n"));
|
|
76 |
break;
|
|
77 |
case KEthDuplexFull:
|
|
78 |
gTest.Printf(_L(" Full\n"));
|
|
79 |
break;
|
|
80 |
case KEthDuplexHalf:
|
|
81 |
gTest.Printf(_L(" Half\n"));
|
|
82 |
break;
|
|
83 |
default:
|
|
84 |
gTest.Printf(_L(" ERROR\n"));
|
|
85 |
}
|
|
86 |
|
|
87 |
gTest.Printf(_L("MAC :"));
|
|
88 |
gTest.Printf(_L(" %2x:%2x:%2x:%2x:%2x:%2x\n\n"),
|
|
89 |
config[2], config[3],
|
|
90 |
config[4], config[5],
|
|
91 |
config[6], config[7]);
|
|
92 |
}
|
|
93 |
|
|
94 |
LOCAL_C void WriteMac()
|
|
95 |
//
|
|
96 |
// Write the new mac address to the card
|
|
97 |
//
|
|
98 |
{
|
|
99 |
TBuf8<8> ioctlBuf;
|
|
100 |
// TEthernetConfigV01 newInfo;
|
|
101 |
|
|
102 |
// TRequestStatus status;
|
|
103 |
TBuf<20> validChars(_L("0123456789abcdef"));
|
|
104 |
TUint8 value;
|
|
105 |
TUint8 upper=0;
|
|
106 |
TChar c;
|
|
107 |
TInt pos;
|
|
108 |
TBool bResult = ETrue;
|
|
109 |
|
|
110 |
TBuf8<32> config;
|
|
111 |
|
|
112 |
// Obtain command line parameters
|
|
113 |
// TPtrC option;
|
|
114 |
|
|
115 |
// CCommandLineArguments* args = CCommandLineArguments::NewLC();
|
|
116 |
TBuf<256> cmd;
|
|
117 |
User::CommandLine(cmd);
|
|
118 |
|
|
119 |
// MAC Address starts at the 4th byte
|
|
120 |
config.SetMax();
|
|
121 |
card.Config(config);
|
|
122 |
|
|
123 |
gTest.Printf(_L("Command length is %d\n"), cmd.Length());
|
|
124 |
|
|
125 |
if (cmd.Length()>0)
|
|
126 |
// if (args->Count() > 2)
|
|
127 |
{
|
|
128 |
// option.Set(args->Arg(1));
|
|
129 |
if(cmd[0]=='-' && (cmd[1]=='s' || cmd[1]=='S'))
|
|
130 |
// if(!option.CompareF(_L("-S")))
|
|
131 |
{
|
|
132 |
ioctlBuf.SetLength(8);
|
|
133 |
ioctlBuf[0] = KEthSpeed10BaseT;
|
|
134 |
// newInfo.iEthSpeed = KEthSpeed10BaseT;
|
|
135 |
ioctlBuf[1] = KEthDuplexHalf;
|
|
136 |
// newInfo.iEthDuplex = KEthDuplexHalf;
|
|
137 |
|
|
138 |
for(int i = 0; i<6; i++)
|
|
139 |
{
|
|
140 |
c = cmd[3+(i*2)];
|
|
141 |
// c = args->Arg(2)[2*i];
|
|
142 |
c.LowerCase();
|
|
143 |
if((pos = validChars.Locate(c))==KErrNotFound)
|
|
144 |
{
|
|
145 |
pos = upper;
|
|
146 |
break;
|
|
147 |
}
|
|
148 |
upper = (TUint8)pos;
|
|
149 |
c = cmd[4+(i*2)];
|
|
150 |
// c = args->Arg(2)[(2*i)+1];
|
|
151 |
c.LowerCase();
|
|
152 |
if((pos = validChars.Locate(c))==KErrNotFound)
|
|
153 |
{
|
|
154 |
User::Leave(KErrNotFound);
|
|
155 |
}
|
|
156 |
value = (TUint8)pos;
|
|
157 |
value = (TUint8)((upper<<4) | value);
|
|
158 |
|
|
159 |
ioctlBuf[i+2] = value;
|
|
160 |
// newInfo.iEthAddress[i] = value;
|
|
161 |
}
|
|
162 |
|
|
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]);
|
|
167 |
|
|
168 |
card.SetMAC(ioctlBuf);
|
|
169 |
// card.IOControl(status,ioctlBuf);
|
|
170 |
gTest.Printf(_L("Done\n"));
|
|
171 |
}
|
|
172 |
else if(cmd[0]=='-' && (cmd[1]=='c' || cmd[1]=='C'))
|
|
173 |
{
|
|
174 |
|
|
175 |
for(int i = 0; i<6; i++)
|
|
176 |
{
|
|
177 |
c = cmd[3+(i*2)];
|
|
178 |
c.LowerCase();
|
|
179 |
if((pos = validChars.Locate(c))==KErrNotFound)
|
|
180 |
{
|
|
181 |
pos = upper;
|
|
182 |
bResult = EFalse;
|
|
183 |
break;
|
|
184 |
}
|
|
185 |
upper = (TUint8)pos;
|
|
186 |
c = cmd[4+(i*2)];
|
|
187 |
|
|
188 |
c.LowerCase();
|
|
189 |
if((pos = validChars.Locate(c))==KErrNotFound)
|
|
190 |
{
|
|
191 |
//User::Leave(KErrNotFound);
|
|
192 |
bResult = EFalse;
|
|
193 |
break;
|
|
194 |
}
|
|
195 |
value = (TUint8)pos;
|
|
196 |
value = (TUint8)((upper<<4) | value);
|
|
197 |
|
|
198 |
if( config[i+2] != value)
|
|
199 |
{
|
|
200 |
bResult = EFalse;
|
|
201 |
break;
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
if( EFalse == bResult )
|
|
206 |
gTest.Printf(_L("Test FAILED\n\n"));
|
|
207 |
else
|
|
208 |
gTest.Printf(_L("Test PASSED\n\n"));
|
|
209 |
|
|
210 |
}
|
|
211 |
else
|
|
212 |
{
|
|
213 |
gTest.Printf(_L("Invalid option"));
|
|
214 |
}
|
|
215 |
}
|
|
216 |
else
|
|
217 |
{
|
|
218 |
gTest.Printf(_L("Call with -s to set new MAC\n"));
|
|
219 |
gTest.Printf(_L(" eg. macset -s 102030405060\n"));
|
|
220 |
|
|
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"));
|
|
223 |
}
|
|
224 |
|
|
225 |
// CleanupStack::PopAndDestroy( /* args */ );
|
|
226 |
}
|
|
227 |
|
|
228 |
|
|
229 |
LOCAL_C TInt InitGlobals()
|
|
230 |
//
|
|
231 |
// Initialise global variables.
|
|
232 |
//
|
|
233 |
{
|
|
234 |
TInt err;
|
|
235 |
TBuf8<8> ioctlBuf;
|
|
236 |
// TRequestStatus status;
|
|
237 |
|
|
238 |
gTest.Printf(_L("**Load LDD\n"));
|
|
239 |
err=User::LoadLogicalDevice(LDD_NAME);
|
|
240 |
if (err!=KErrNone && err!=KErrAlreadyExists)
|
|
241 |
return(err);
|
|
242 |
|
|
243 |
gTest.Printf(_L("**Load PDD\n"));
|
|
244 |
err=User::LoadPhysicalDevice(PDD_NAME);
|
|
245 |
if (err!=KErrNone && err!=KErrAlreadyExists)
|
|
246 |
return(err);
|
|
247 |
|
|
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"));
|
|
254 |
|
|
255 |
card.Caps(ioctlBuf);
|
|
256 |
// card.IOControl(status,ioctlBuf);
|
|
257 |
// if(ioctlBuf[0] != KEventPCCardReady)
|
|
258 |
// {
|
|
259 |
// card.Close();
|
|
260 |
// User::Leave(KErrNotReady);
|
|
261 |
// }
|
|
262 |
gTest.Printf(_L("**Init Done\n"));
|
|
263 |
return KErrNone;
|
|
264 |
}
|
|
265 |
|
|
266 |
LOCAL_C void DestroyGlobals()
|
|
267 |
//
|
|
268 |
// Free global variables
|
|
269 |
//
|
|
270 |
{
|
|
271 |
gTest.Printf(_L("**Free PDD\n"));
|
|
272 |
User::FreePhysicalDevice(PDD_NAME);
|
|
273 |
gTest.Printf(_L("**Free LDD\n"));
|
|
274 |
User::FreeLogicalDevice(LDD_NAME);
|
|
275 |
|
|
276 |
|
|
277 |
// gFs.Close();
|
|
278 |
}
|
|
279 |
|
|
280 |
LOCAL_C void RunMacSetL()
|
|
281 |
//
|
|
282 |
// Run all the tests
|
|
283 |
//
|
|
284 |
{
|
|
285 |
|
|
286 |
TInt ret = InitGlobals();
|
|
287 |
if(ret != KErrNone)
|
|
288 |
return;
|
|
289 |
|
|
290 |
ReadMac();
|
|
291 |
WriteMac();
|
|
292 |
DestroyGlobals();
|
|
293 |
}
|
|
294 |
|
|
295 |
EXPORT_C TInt E32Main()
|
|
296 |
//
|
|
297 |
// Main
|
|
298 |
//
|
|
299 |
{
|
|
300 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
301 |
CActiveScheduler* theActiveScheduler = new CActiveScheduler();
|
|
302 |
CActiveScheduler::Install(theActiveScheduler);
|
|
303 |
|
|
304 |
__UHEAP_MARK;
|
|
305 |
|
|
306 |
TRAPD(err,RunMacSetL());
|
|
307 |
if (err!=KErrNone)
|
|
308 |
gTest.Printf(_L("ERROR: Leave %d\n"),err);
|
|
309 |
|
|
310 |
gTest.Printf(_L("Press any key ...\n"));
|
|
311 |
gTest.Getch();
|
|
312 |
gTest.Close();
|
|
313 |
|
|
314 |
__UHEAP_MARKEND;
|
|
315 |
|
|
316 |
delete cleanup;
|
|
317 |
delete theActiveScheduler;
|
|
318 |
return KErrNone;
|
|
319 |
}
|