|
1 # |
|
2 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "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 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # This script is designed to provide a working ethernet setup |
|
16 # for EKA1 or EKA2. It works by running Netcards.exe |
|
17 # then taking the output from Netcards (ethernet.ini) |
|
18 # and appending the ethernet settings to epoc.ini for EKA2 |
|
19 # or creating ethermac.dat and etherdriver.dat for EKA1 |
|
20 # The script can |
|
21 # - create a working ethernet setup with "ethernet" config option |
|
22 # - restore previous setup with "restore" config option |
|
23 # Please note: The script assumes that target wins is running on EKA1 |
|
24 # Copied from configchange.pl to make use of environment varible for mac address |
|
25 # Copied from configchangebats.pl to adapt for multiple network cards in "Blade" type servers. |
|
26 # |
|
27 |
|
28 use Getopt::Long; |
|
29 use Cwd; |
|
30 |
|
31 use Getopt::Long; |
|
32 use Cwd; |
|
33 |
|
34 my $config="default"; |
|
35 my $target="default"; |
|
36 my $kernel="default"; |
|
37 my $showhelp='0'; |
|
38 |
|
39 my $etherNif; |
|
40 my $etherMac = $ENV{'WINSCW_MAC'}; |
|
41 my $etherSpeed; |
|
42 |
|
43 # this variable is passed as an argument to netcards.exe |
|
44 # specifies which interface to use in case of multiple interfaces |
|
45 |
|
46 my $interface=0; |
|
47 |
|
48 $/ = "\n"; |
|
49 |
|
50 GetOptions('config=s' => \$config, 'kernel=s' => \$kernel, 'target=s' => \$target, 'variant=s' => \$variant, 'help' => \$showhelp, 'interface:i' => \$interface); |
|
51 |
|
52 $config = lc( $config ); |
|
53 $kernel = lc( $kernel ); |
|
54 $target = lc( $target ); |
|
55 $variant = lc( $variant ); |
|
56 |
|
57 |
|
58 |
|
59 if( $showhelp || ( $kernel ne "eka1" && $kernel ne "eka2" ) || |
|
60 ( $target ne "wins" && $target ne "winscw" ) || |
|
61 ( $config ne "ethernetwithcommdb" && $config ne "restorecommdb" && $config ne "ethernetnocommdb" ) || |
|
62 ( $variant ne "udeb" && $variant ne "urel" ) ) |
|
63 { |
|
64 print "Command usage: configchange --config [ethernetWithCommDB|restoreCommDB|ethernetNoCommDB] --kernel [EKA1|EKA2] --target [wins|winscw] --variant [UDEB|UREL]\n"; |
|
65 print "\t\t--config \tSelect required configuration\n"; |
|
66 print "\t\t--kernel \tKernel variant\n"; |
|
67 print "\t\t--target \tTarget emulator\n"; |
|
68 print "\t\t--variant \tBuild type\n"; |
|
69 print "\t\t--interface \tInterface Number\n"; |
|
70 print "\t\t--help \tThis text\n"; |
|
71 exit 0; |
|
72 } |
|
73 |
|
74 my $epocroot = &getEpocroot; |
|
75 my $drive = &getDrive; |
|
76 |
|
77 if($ENV{'SERVER_TYPE'} && $ENV{'SERVER_TYPE'} =~ /blade/i){ |
|
78 $interface=1; |
|
79 } |
|
80 |
|
81 |
|
82 my $netIF = ""; |
|
83 my $netConfigOutput = `net config rdr`; |
|
84 |
|
85 # Sample output: |
|
86 #J:\epoc32\winscw\c>net config rdr |
|
87 #Computer name \\SYWINPAP0005 |
|
88 #Full Computer name SYWINPAP0005.prod.ad.symbian.intra |
|
89 #User name extkesavanathimoolam |
|
90 # |
|
91 #Workstation active on |
|
92 # NetbiosSmb (000000000000) |
|
93 # NetBT_Tcpip_{0B887A6F-A34C-4A43-85A4-FA5D58BEEE8A} (00215E2CB2F6) |
|
94 |
|
95 |
|
96 # capture the network-interface info to compare it later with netcards output |
|
97 if($netConfigOutput =~ /NetBT_Tcpip_\{(.*)?\}/i){ |
|
98 $netIF = $1; |
|
99 } |
|
100 |
|
101 |
|
102 # netcards output sample |
|
103 #J:\epoc32\winscw\c>\epoc32\tools\netcards.exe 1 |
|
104 #Adapters installed: |
|
105 #N/A - \Device\NPF_GenericDialupAdapter |
|
106 # Adapter for generic dialup and VPN capture |
|
107 # |
|
108 # 1 - \Device\NPF_{0B887A6F-A34C-4A43-85A4-FA5D58BEEE8A} |
|
109 # Broadcom Advanced Server Program Driver for Windows Server 2003 with SNP |
|
110 # |
|
111 # |
|
112 # 2 - \Device\NPF_{11F02767-7BDE-49FF-87F2-FD7F46FA8C60} |
|
113 # Broadcom L2 NDIS client driver |
|
114 # |
|
115 # 3 - \Device\NPF_{9672396E-2361-42BF-80CF-1E03AF7BD59F} |
|
116 # Broadcom L2 NDIS client driver |
|
117 # |
|
118 #Using adapter 1 |
|
119 #Physical address read: 00:21:5e:2c:b2:f6 |
|
120 #Writing settings to ethernet.ini. |
|
121 |
|
122 |
|
123 $netCardsCommand = "$drive\\$epocroot\\epoc32\\tools\\netcards $interface"; |
|
124 foreach (split("\n",`$netCardsCommand`)){ |
|
125 if(/\s*(\d)\s+\-\s+.*?$netIF/){ |
|
126 $interface = $1; |
|
127 last; |
|
128 } |
|
129 } |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 if( $config ne "restorecommdb" ) |
|
135 { |
|
136 # must be creating some ethernet setup |
|
137 if( $config eq "ethernetwithcommdb" ) |
|
138 { |
|
139 # write an appropriate commDB setup |
|
140 print( "Setting up CommDB for ethernet\n" ); |
|
141 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ceddump" ) == 0 |
|
142 or die "Error running ceddump!\n"; |
|
143 system( "move $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" ) == 0 |
|
144 or die "Failed to rename cedout.cfg!\n"; |
|
145 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -dtextshell -- -i c:\\EthernetCed.xml") == 0 |
|
146 or die "Error running ced!\n"; |
|
147 } |
|
148 print( "Running Netcards to obtain adapter info\n" ); |
|
149 system( "$drive\\$epocroot\\epoc32\\tools\\netcards $interface" ) == 0 |
|
150 or die "Error running netcards!\n"; |
|
151 |
|
152 open ( INFILE, "ethernet.ini" ) or die "Can't find netcards output file, ethernet.ini!\n"; # get from current directory where netcards wrote it to |
|
153 |
|
154 if ($kernel eq "eka1") |
|
155 { |
|
156 open ( ETHERDRV, ">$drive\\$epocroot\\epoc32\\$target\\c\\system\\data\\etherdriver.dat" ) or die "Can't open $drive\\$epocroot\\epoc32\\$target\\c\\system\\data\\etherdriver.dat!\n"; |
|
157 } |
|
158 |
|
159 while( <INFILE> ) |
|
160 { |
|
161 chomp; |
|
162 my $sLine = $_; |
|
163 |
|
164 if( $sLine =~ /ETHER_NIF=(.*)/i ) |
|
165 { |
|
166 #print "Matched ETHER_NIF\n"; |
|
167 if ($kernel eq "eka1") |
|
168 { |
|
169 print ETHERDRV "$1"; |
|
170 } |
|
171 else |
|
172 { |
|
173 $etherNif = $1; |
|
174 } |
|
175 } |
|
176 elsif( $sLine =~ /ETHER_SPEED=(.*)/i ) |
|
177 { |
|
178 #print "Matched ETHER_SPEED\n"; |
|
179 if ($kernel eq "eka2") |
|
180 { |
|
181 $etherSpeed = $1; |
|
182 } |
|
183 } |
|
184 #print "line: $sLine\n"; |
|
185 } |
|
186 if ($kernel eq "eka1") |
|
187 { |
|
188 close( ETHERDRV ); |
|
189 } |
|
190 else |
|
191 { |
|
192 # do the insertion to epoc.ini |
|
193 &generateEpocIni; |
|
194 } |
|
195 close( INFILE ); |
|
196 } |
|
197 else |
|
198 { |
|
199 if( -f "$drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" ) |
|
200 { |
|
201 system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -i c:\\nonethernetced.cfg" ) == 0 |
|
202 or die "Can't find backup ced file!\n"; |
|
203 system( "move $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg" ) == 0 |
|
204 or die "Can't rename backup ced file!\n"; |
|
205 } |
|
206 else |
|
207 { |
|
208 print "No restore file found!\n"; |
|
209 } |
|
210 } |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 # |
|
216 # Determines, validates, and returns EPOCROOT. |
|
217 # |
|
218 sub getEpocroot |
|
219 { |
|
220 my $epocroot = $ENV{EPOCROOT}; |
|
221 die "ERROR: Must set the EPOCROOT environment variable.\n" |
|
222 if (!defined($epocroot)); |
|
223 $epocroot =~ s-/-\\-go; # for those working with UNIX shells |
|
224 die "ERROR: EPOCROOT must be an absolute path, " . |
|
225 "not containing a drive letter.\n" if ($epocroot !~ /^\\/); |
|
226 die "ERROR: EPOCROOT must not be a UNC path.\n" if ($epocroot =~ /^\\\\/); |
|
227 die "ERROR: EPOCROOT must end with a backslash.\n" if ($epocroot !~ /\\$/); |
|
228 die "ERROR: EPOCROOT must specify an existing directory.\n" |
|
229 if (!-d $epocroot); |
|
230 return $epocroot; |
|
231 } |
|
232 |
|
233 # |
|
234 # Determines and returns the current drive, if any. |
|
235 # |
|
236 sub getDrive |
|
237 { |
|
238 my $wd = cwd; |
|
239 my $drive; |
|
240 if($wd =~ /^([a-zA-Z]:)/) { |
|
241 $drive = $1; |
|
242 } else { |
|
243 # Perhaps we're on a machine that has no drives. |
|
244 $drive = ""; |
|
245 } |
|
246 return $drive; |
|
247 } |
|
248 |
|
249 # |
|
250 # |
|
251 # |
|
252 sub generateEpocIni |
|
253 { |
|
254 my @outLines; |
|
255 my $length = 0; |
|
256 my $needToAppend = TRUE; |
|
257 my $epocIniAlreadyExists = FALSE; |
|
258 my $finished = FALSE; |
|
259 print "generating epoc ini\n"; |
|
260 if ( -e "$drive\\$epocroot\\epoc32\\data\\epoc.ini" ) |
|
261 { |
|
262 $epocIniAlreadyExists = TRUE; |
|
263 open( EPOCINI, "+<$drive\\$epocroot\\epoc32\\data\\epoc.ini" ); |
|
264 seek( EPOCINI, 0, 0 ); |
|
265 while( <EPOCINI> ) |
|
266 { |
|
267 chomp; |
|
268 my $sLine = $_; |
|
269 if( $sLine =~ /ETHER_NIF=(.*)/i ) |
|
270 { |
|
271 #print "matched etherNIF\n"; |
|
272 $length = length( $etherNif ); |
|
273 |
|
274 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherNif; |
|
275 $needToAppend = FALSE; |
|
276 } |
|
277 elsif( $sLine =~ /ETHER_MAC=(.*)/i ) |
|
278 { |
|
279 print "Matched ETHER_MAC\n"; |
|
280 $length = length( $etherMac ); |
|
281 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherMac; |
|
282 $needToAppend = FALSE; |
|
283 } |
|
284 elsif( $sLine =~ /ETHER_SPEED=(.*)/i ) |
|
285 { |
|
286 #print "Matched etherSpeed\n"; |
|
287 $length = length( $etherSpeed ); |
|
288 substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherSpeed; |
|
289 $needToAppend = FALSE; |
|
290 } |
|
291 push( @outLines, $sLine ); |
|
292 push( @outLines, "\n" ); |
|
293 } |
|
294 if ( $needToAppend eq FALSE ) |
|
295 { |
|
296 print "Writing new settings into epoc.ini\n"; |
|
297 # we have read the entire file and replaced what we need to |
|
298 # now lets write it back to the file |
|
299 seek( EPOCINI, 0, 0 ); |
|
300 print EPOCINI @outLines; |
|
301 $finished = TRUE; |
|
302 } |
|
303 close ( EPOCINI ); |
|
304 } |
|
305 |
|
306 if ( $finished eq FALSE ) |
|
307 { |
|
308 if ( ($needToAppend eq TRUE) && ($epocIniAlreadyExists eq TRUE) ) |
|
309 { |
|
310 print "Appending settings to current epoc.ini\n"; |
|
311 # we must append all the settings onto the end of the current epoc.ini |
|
312 open( EPOCINI, ">>$drive\\$epocroot\\epoc32\\data\\epoc.ini" ) or die "Can't open epoc.ini!\n"; |
|
313 } |
|
314 elsif ( $epocIniAlreadyExists eq FALSE ) |
|
315 { |
|
316 print "Creating new epoc.ini\n"; |
|
317 # create new file |
|
318 open( EPOCINI, ">$drive\\$epocroot\\epoc32\\data\\epoc.ini" ); |
|
319 } |
|
320 |
|
321 print EPOCINI "\nETHER_NIF="; |
|
322 print EPOCINI "$etherNif\n"; |
|
323 print EPOCINI "ETHER_MAC="; |
|
324 print EPOCINI "$etherMac\n"; |
|
325 print EPOCINI "ETHER_SPEED="; |
|
326 print EPOCINI "$etherSpeed\n"; |
|
327 close ( EPOCINI ); |
|
328 } |
|
329 } |