|
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 "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 <EtherCardApi.h> |
|
23 #include <EtherCardIoc.h> |
|
24 |
|
25 GLDEF_D RTest gTest(_L("macset utility")); |
|
26 GLDEF_D RFs gFs; |
|
27 GLDEF_D RPcmNetCardIf card; |
|
28 |
|
29 |
|
30 #define PDD_NAME _L("EtherSMC") |
|
31 #define LDD_NAME _L("EtherCard") |
|
32 |
|
33 LOCAL_C void ReadMac() |
|
34 // |
|
35 // Dump narrow text file to console, comms & debug (WINS) |
|
36 // |
|
37 { |
|
38 TBuf8<32> config; |
|
39 |
|
40 // MAC Address starts at the 4th byte |
|
41 config.SetMax(); |
|
42 card.GetConfig(config); |
|
43 |
|
44 gTest.Printf(_L("Ethernet Status :")); |
|
45 if (config[0] == KEthCardReady) |
|
46 gTest.Printf(_L(" Ready\n")); |
|
47 else |
|
48 gTest.Printf(_L(" NOT Ready\n")); |
|
49 |
|
50 gTest.Printf(_L("Ethernet Speed :")); |
|
51 switch (config[1]) |
|
52 { |
|
53 case KEthSpeedUnknown: |
|
54 gTest.Printf(_L(" Unknown\n")); |
|
55 break; |
|
56 case KEthSpeedAuto: |
|
57 gTest.Printf(_L(" Auto\n")); |
|
58 break; |
|
59 case KEthSpeed10BaseT: |
|
60 gTest.Printf(_L(" 10 MBit\n")); |
|
61 break; |
|
62 case KEthSpeed100BaseTX: |
|
63 gTest.Printf(_L(" 100 MBit\n")); |
|
64 break; |
|
65 default: |
|
66 gTest.Printf(_L(" ERROR\n")); |
|
67 } |
|
68 |
|
69 gTest.Printf(_L("Duplex Setting :")); |
|
70 switch (config[2]) |
|
71 { |
|
72 case KEthDuplexUnknown: |
|
73 gTest.Printf(_L(" Unknown\n")); |
|
74 break; |
|
75 case KEthDuplexAuto: |
|
76 gTest.Printf(_L(" Auto\n")); |
|
77 break; |
|
78 case KEthDuplexFull: |
|
79 gTest.Printf(_L(" Full\n")); |
|
80 break; |
|
81 case KEthDuplexHalf: |
|
82 gTest.Printf(_L(" Half\n")); |
|
83 break; |
|
84 default: |
|
85 gTest.Printf(_L(" ERROR\n")); |
|
86 } |
|
87 |
|
88 gTest.Printf(_L("MAC :")); |
|
89 gTest.Printf(_L(" %2x:%2x:%2x:%2x:%2x:%2x\n\n"), |
|
90 config[3], config[4], |
|
91 config[5], config[6], |
|
92 config[7], config[8]); |
|
93 } |
|
94 |
|
95 LOCAL_C void WriteMac() |
|
96 // |
|
97 // Write the new mac address to the card |
|
98 // |
|
99 { |
|
100 TBuf8<8> ioctlBuf; |
|
101 TRequestStatus status; |
|
102 TBuf<20> validChars(_L("0123456789abcdef")); |
|
103 TUint8 value; |
|
104 TUint8 upper=0; |
|
105 TChar c; |
|
106 TInt pos; |
|
107 |
|
108 // Obtain command line parameters |
|
109 TPtrC option; |
|
110 |
|
111 CCommandLineArguments* args = CCommandLineArguments::NewLC(); |
|
112 |
|
113 if (args->Count() > 2) |
|
114 { |
|
115 option.Set(args->Arg(1)); |
|
116 |
|
117 if(!option.CompareF(_L("-S"))) |
|
118 { |
|
119 ioctlBuf.SetLength(7); |
|
120 ioctlBuf[0] = KIoControlSetMACAddress; |
|
121 |
|
122 for(int i = 0; i<6; i++) |
|
123 { |
|
124 c = args->Arg(2)[2*i]; |
|
125 c.LowerCase(); |
|
126 if((pos = validChars.Locate(c))==KErrNotFound) |
|
127 { |
|
128 pos = upper; |
|
129 break; |
|
130 } |
|
131 upper = (TUint8)pos; |
|
132 c = args->Arg(2)[(2*i)+1]; |
|
133 c.LowerCase(); |
|
134 if((pos = validChars.Locate(c))==KErrNotFound) |
|
135 { |
|
136 User::Leave(KErrNotFound); |
|
137 } |
|
138 value = (TUint8)pos; |
|
139 value = (TUint8)((upper<<4) | value); |
|
140 |
|
141 ioctlBuf[i+1] = value; |
|
142 } |
|
143 |
|
144 gTest.Printf(_L("\nSetting MAC to %2x:%2x:%2x:%2x:%2x:%2x\n"), |
|
145 ioctlBuf[1], ioctlBuf[2], |
|
146 ioctlBuf[3], ioctlBuf[4], |
|
147 ioctlBuf[5], ioctlBuf[6]); |
|
148 |
|
149 card.IOControl(status,ioctlBuf); |
|
150 gTest.Printf(_L("Done\n")); |
|
151 } |
|
152 else |
|
153 { |
|
154 gTest.Printf(_L("Invalid option")); |
|
155 } |
|
156 } |
|
157 else |
|
158 { |
|
159 gTest.Printf(_L("Call with -s to set new MAC\n")); |
|
160 gTest.Printf(_L(" eg. macset -s 102030405060\n")); |
|
161 } |
|
162 |
|
163 CleanupStack::PopAndDestroy( /* args */ ); |
|
164 } |
|
165 |
|
166 |
|
167 LOCAL_C TInt InitGlobals() |
|
168 // |
|
169 // Initialise global variables. |
|
170 // |
|
171 { |
|
172 TInt err; |
|
173 TBuf8<8> ioctlBuf; |
|
174 TRequestStatus status; |
|
175 |
|
176 err=User::LoadPhysicalDevice(PDD_NAME); |
|
177 if (err!=KErrNone && err!=KErrAlreadyExists) |
|
178 return(err); |
|
179 err=User::LoadLogicalDevice(LDD_NAME ); |
|
180 if (err!=KErrNone && err!=KErrAlreadyExists) |
|
181 return(err); |
|
182 |
|
183 User::LeaveIfError(card.Open(card.VersionRequired(),0,NULL)); |
|
184 ioctlBuf.SetLength(1); |
|
185 ioctlBuf[0] = KIoControlGetStatus; |
|
186 |
|
187 card.IOControl(status,ioctlBuf); |
|
188 if(ioctlBuf[0] != KEventPCCardReady) |
|
189 { |
|
190 card.Close(); |
|
191 User::Leave(KErrNotReady); |
|
192 } |
|
193 |
|
194 err=gFs.Connect(); |
|
195 gTest(err==KErrNone); |
|
196 |
|
197 // Force console creation |
|
198 gTest.Printf(_L("")); |
|
199 |
|
200 return KErrNone; |
|
201 } |
|
202 |
|
203 LOCAL_C void DestroyGlobals() |
|
204 // |
|
205 // Free global variables |
|
206 // |
|
207 { |
|
208 User::FreeLogicalDevice(_L("EtherCard")); |
|
209 User::FreePhysicalDevice(_L("EtherCard.Smc")); |
|
210 |
|
211 gFs.Close(); |
|
212 } |
|
213 |
|
214 LOCAL_C void RunMacSetL() |
|
215 // |
|
216 // Run all the tests |
|
217 // |
|
218 { |
|
219 |
|
220 TInt ret = InitGlobals(); |
|
221 if(ret != KErrNone) |
|
222 return; |
|
223 |
|
224 ReadMac(); |
|
225 WriteMac(); |
|
226 DestroyGlobals(); |
|
227 } |
|
228 |
|
229 EXPORT_C TInt E32Main() |
|
230 // |
|
231 // Main |
|
232 // |
|
233 { |
|
234 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
235 CActiveScheduler* theActiveScheduler = new CActiveScheduler(); |
|
236 CActiveScheduler::Install(theActiveScheduler); |
|
237 |
|
238 __UHEAP_MARK; |
|
239 |
|
240 TRAPD(err,RunMacSetL()); |
|
241 if (err!=KErrNone) |
|
242 gTest.Printf(_L("ERROR: Leave %d\n"),err); |
|
243 |
|
244 gTest.Printf(_L("Press any key ...\n")); |
|
245 gTest.Getch(); |
|
246 gTest.Close(); |
|
247 |
|
248 __UHEAP_MARKEND; |
|
249 |
|
250 delete cleanup; |
|
251 delete theActiveScheduler; |
|
252 return KErrNone; |
|
253 } |