os/security/cryptomgmtlibs/securitytestfw/test/autotesting/configchangebats.pl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/autotesting/configchangebats.pl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,334 @@
     1.4 +#
     1.5 +# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +# All rights reserved.
     1.7 +# This component and the accompanying materials are made available
     1.8 +# under the terms of the License "Eclipse Public License v1.0"
     1.9 +# which accompanies this distribution, and is available
    1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +#
    1.12 +# Initial Contributors:
    1.13 +# Nokia Corporation - initial contribution.
    1.14 +#
    1.15 +# Contributors:
    1.16 +#
    1.17 +# Description: 
    1.18 +# This script is designed to provide a working ethernet setup
    1.19 +# for EKA1 or EKA2.  It works by running Netcards.exe
    1.20 +# then taking the output from Netcards (ethernet.ini)
    1.21 +# and appending the ethernet settings to epoc.ini for EKA2
    1.22 +# or creating ethermac.dat and etherdriver.dat for EKA1
    1.23 +# The script can
    1.24 +# - create a working ethernet setup with "ethernet" config option
    1.25 +# - restore previous setup with "restore" config option
    1.26 +# Please note: The script assumes that target wins is running on EKA1
    1.27 +# Copied from configchange.pl to make use of environment varible for mac address
    1.28 +# Copied from configchangebats.pl to adapt for multiple network cards in "Blade" type servers.
    1.29 +#
    1.30 +
    1.31 +use Getopt::Long;
    1.32 +use Cwd;
    1.33 +
    1.34 +use Getopt::Long;
    1.35 +use Cwd;
    1.36 +
    1.37 +my $config="default";
    1.38 +my $target="default";
    1.39 +my $kernel="default";
    1.40 +my $showhelp='0';
    1.41 +
    1.42 +my $etherNif;
    1.43 +my $etherMac = $ENV{'WINSCW_MAC'};
    1.44 +my $etherSpeed; 
    1.45 +
    1.46 +# this variable is passed as an argument to netcards.exe
    1.47 +# specifies which interface to use in case of multiple interfaces
    1.48 +
    1.49 +my $interface=0;
    1.50 +
    1.51 +$/ = "\n";
    1.52 +
    1.53 +GetOptions('config=s' => \$config, 'kernel=s' => \$kernel, 'target=s' => \$target, 'variant=s' => \$variant, 'help' => \$showhelp, 'interface:i' => \$interface);
    1.54 +
    1.55 +$config = lc( $config );
    1.56 +$kernel = lc( $kernel );
    1.57 +$target = lc( $target );
    1.58 +$variant = lc( $variant );
    1.59 +
    1.60 +
    1.61 +
    1.62 +if( $showhelp || ( $kernel ne "eka1" && $kernel ne "eka2" ) ||
    1.63 + ( $target ne "wins" && $target ne "winscw" ) ||
    1.64 + ( $config ne "ethernetwithcommdb" && $config ne "restorecommdb" && $config ne "ethernetnocommdb" ) ||
    1.65 + ( $variant ne "udeb" && $variant ne "urel" ) )
    1.66 +	{
    1.67 +	print "Command usage: configchange --config [ethernetWithCommDB|restoreCommDB|ethernetNoCommDB] --kernel [EKA1|EKA2] --target [wins|winscw] --variant [UDEB|UREL]\n";
    1.68 +	print "\t\t--config   \tSelect required configuration\n";
    1.69 +	print "\t\t--kernel   \tKernel variant\n";
    1.70 +	print "\t\t--target   \tTarget emulator\n";
    1.71 +	print "\t\t--variant  \tBuild type\n";
    1.72 +	print "\t\t--interface  \tInterface Number\n";
    1.73 +	print "\t\t--help   \tThis text\n";
    1.74 +	exit 0;
    1.75 +	}
    1.76 +
    1.77 +my $epocroot = &getEpocroot;
    1.78 +my $drive = &getDrive;
    1.79 +
    1.80 +if($ENV{'SERVER_TYPE'} && $ENV{'SERVER_TYPE'} =~ /blade/i){
    1.81 +  $interface=1;
    1.82 +}
    1.83 +
    1.84 +
    1.85 +my $netIF = "";
    1.86 +my $netConfigOutput  = `net config rdr`;
    1.87 +
    1.88 +# Sample output:
    1.89 +#J:\epoc32\winscw\c>net config rdr
    1.90 +#Computer name                        \\SYWINPAP0005
    1.91 +#Full Computer name                   SYWINPAP0005.prod.ad.symbian.intra
    1.92 +#User name                            extkesavanathimoolam
    1.93 +#
    1.94 +#Workstation active on
    1.95 +#        NetbiosSmb (000000000000)
    1.96 +#        NetBT_Tcpip_{0B887A6F-A34C-4A43-85A4-FA5D58BEEE8A} (00215E2CB2F6)
    1.97 +
    1.98 +
    1.99 +# capture the network-interface info to compare it later with netcards output
   1.100 +if($netConfigOutput =~ /NetBT_Tcpip_\{(.*)?\}/i){
   1.101 +        $netIF = $1;
   1.102 +}
   1.103 +
   1.104 +
   1.105 +# netcards output sample
   1.106 +#J:\epoc32\winscw\c>\epoc32\tools\netcards.exe 1
   1.107 +#Adapters installed:
   1.108 +#N/A - \Device\NPF_GenericDialupAdapter
   1.109 +#        Adapter for generic dialup and VPN capture
   1.110 +#
   1.111 +#  1 - \Device\NPF_{0B887A6F-A34C-4A43-85A4-FA5D58BEEE8A}
   1.112 +#        Broadcom Advanced Server Program Driver for Windows Server 2003 with SNP
   1.113 +#
   1.114 +#
   1.115 +#  2 - \Device\NPF_{11F02767-7BDE-49FF-87F2-FD7F46FA8C60}
   1.116 +#        Broadcom L2 NDIS client driver
   1.117 +#
   1.118 +#  3 - \Device\NPF_{9672396E-2361-42BF-80CF-1E03AF7BD59F}
   1.119 +#        Broadcom L2 NDIS client driver
   1.120 +#
   1.121 +#Using adapter 1
   1.122 +#Physical address read: 00:21:5e:2c:b2:f6
   1.123 +#Writing settings to ethernet.ini.
   1.124 +
   1.125 +
   1.126 +$netCardsCommand = "$drive\\$epocroot\\epoc32\\tools\\netcards $interface";
   1.127 +foreach (split("\n",`$netCardsCommand`)){
   1.128 +        if(/\s*(\d)\s+\-\s+.*?$netIF/){
   1.129 +               $interface = $1;
   1.130 +			   last;
   1.131 +	}
   1.132 +}
   1.133 +
   1.134 +
   1.135 + 
   1.136 +
   1.137 +if( $config ne "restorecommdb" )
   1.138 +	{
   1.139 +	# must be creating some ethernet setup
   1.140 +	if( $config eq "ethernetwithcommdb" )
   1.141 +		{
   1.142 +		# write an appropriate commDB setup
   1.143 +		print( "Setting up CommDB for ethernet\n" );
   1.144 +		system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ceddump" ) == 0 
   1.145 +				or die "Error running ceddump!\n";
   1.146 +		system( "move $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" ) == 0
   1.147 +				or die "Failed to rename cedout.cfg!\n";
   1.148 +		system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -dtextshell -- -i c:\\EthernetCed.xml") == 0
   1.149 +				or die "Error running ced!\n";
   1.150 +  		}
   1.151 +  	print( "Running Netcards to obtain adapter info\n" );
   1.152 +	system( "$drive\\$epocroot\\epoc32\\tools\\netcards $interface" ) == 0
   1.153 +			or die "Error running netcards!\n";
   1.154 +
   1.155 +	open ( INFILE, "ethernet.ini" ) or die "Can't find netcards output file, ethernet.ini!\n";					 # get from current directory where netcards wrote it to
   1.156 +
   1.157 +	if ($kernel eq "eka1")
   1.158 +		{
   1.159 +	   	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";
   1.160 +	   	}
   1.161 +
   1.162 +	while( <INFILE> )
   1.163 +		{
   1.164 +		chomp;
   1.165 +	   	my $sLine = $_;
   1.166 +
   1.167 +		if( $sLine =~ /ETHER_NIF=(.*)/i )
   1.168 +			{
   1.169 +			#print "Matched ETHER_NIF\n";
   1.170 +			if ($kernel eq "eka1")
   1.171 +				{
   1.172 +				print ETHERDRV "$1";
   1.173 +    			}
   1.174 +			else
   1.175 +				{
   1.176 +				$etherNif = $1;
   1.177 +				}
   1.178 +			}
   1.179 +		elsif( $sLine =~ /ETHER_SPEED=(.*)/i )
   1.180 +			{
   1.181 +			#print "Matched ETHER_SPEED\n";
   1.182 +			if ($kernel eq "eka2")
   1.183 +				{
   1.184 +				$etherSpeed = $1;
   1.185 +    			}
   1.186 +			}
   1.187 +		#print "line: $sLine\n";
   1.188 +		}
   1.189 +	if ($kernel eq "eka1")
   1.190 +		{
   1.191 +		close( ETHERDRV );
   1.192 +  		}
   1.193 +  	else
   1.194 +  		{
   1.195 +  		# do the insertion to epoc.ini
   1.196 +  		&generateEpocIni;
   1.197 +    	}
   1.198 +	close( INFILE );
   1.199 +	}
   1.200 +else
   1.201 +	{
   1.202 +	if( -f "$drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" )
   1.203 +		{
   1.204 +		system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -i c:\\nonethernetced.cfg" ) == 0
   1.205 +				or die "Can't find backup ced file!\n";
   1.206 +		system( "move $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg" ) == 0
   1.207 +				or die "Can't rename backup ced file!\n";
   1.208 +		}
   1.209 +	else
   1.210 +		{
   1.211 +		print "No restore file found!\n";
   1.212 +		}
   1.213 +	}
   1.214 +
   1.215 +
   1.216 +
   1.217 +
   1.218 +#
   1.219 +# Determines, validates, and returns EPOCROOT.
   1.220 +#
   1.221 +sub getEpocroot
   1.222 +{
   1.223 +    my $epocroot = $ENV{EPOCROOT};
   1.224 +    die "ERROR: Must set the EPOCROOT environment variable.\n"
   1.225 +	if (!defined($epocroot));
   1.226 +    $epocroot =~ s-/-\\-go;	# for those working with UNIX shells
   1.227 +    die "ERROR: EPOCROOT must be an absolute path, " .
   1.228 +	"not containing a drive letter.\n" if ($epocroot !~ /^\\/);
   1.229 +    die "ERROR: EPOCROOT must not be a UNC path.\n" if ($epocroot =~ /^\\\\/);
   1.230 +    die "ERROR: EPOCROOT must end with a backslash.\n" if ($epocroot !~ /\\$/);
   1.231 +    die "ERROR: EPOCROOT must specify an existing directory.\n"
   1.232 +	if (!-d $epocroot);
   1.233 +    return $epocroot;
   1.234 +}
   1.235 +
   1.236 +#
   1.237 +# Determines and returns the current drive, if any.
   1.238 +#
   1.239 +sub getDrive
   1.240 +{
   1.241 +    my $wd = cwd;
   1.242 +    my $drive;
   1.243 +    if($wd =~ /^([a-zA-Z]:)/) {
   1.244 +	$drive = $1;
   1.245 +    } else {
   1.246 +	# Perhaps we're on a machine that has no drives.
   1.247 +	$drive = "";
   1.248 +    }
   1.249 +    return $drive;
   1.250 +}
   1.251 +
   1.252 +#
   1.253 +#
   1.254 +#
   1.255 +sub generateEpocIni
   1.256 +{
   1.257 +	my @outLines;
   1.258 +	my $length = 0;
   1.259 +	my $needToAppend = TRUE;
   1.260 +	my $epocIniAlreadyExists = FALSE;
   1.261 +	my $finished = FALSE;
   1.262 + 	print "generating epoc ini\n";
   1.263 +	if ( -e "$drive\\$epocroot\\epoc32\\data\\epoc.ini" )
   1.264 +	   {
   1.265 +	   $epocIniAlreadyExists = TRUE;
   1.266 + 	   open( EPOCINI, "+<$drive\\$epocroot\\epoc32\\data\\epoc.ini" );
   1.267 +	   seek( EPOCINI, 0, 0 );
   1.268 +	   while( <EPOCINI> )
   1.269 +	   		{
   1.270 +			chomp;
   1.271 +	   		my $sLine = $_;
   1.272 +			if( $sLine =~ /ETHER_NIF=(.*)/i )
   1.273 +				{
   1.274 +				#print "matched etherNIF\n";
   1.275 +				$length = length( $etherNif );
   1.276 +				
   1.277 +    			substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherNif;
   1.278 +				$needToAppend = FALSE;
   1.279 +				}
   1.280 +			elsif( $sLine =~ /ETHER_MAC=(.*)/i )
   1.281 +				{
   1.282 +				print "Matched ETHER_MAC\n";
   1.283 +				$length = length( $etherMac );
   1.284 +				substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherMac;
   1.285 +				$needToAppend = FALSE;
   1.286 +	    		}
   1.287 +			elsif( $sLine =~ /ETHER_SPEED=(.*)/i )
   1.288 +				{
   1.289 +				#print "Matched etherSpeed\n";
   1.290 +    			$length = length( $etherSpeed );
   1.291 +				substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherSpeed;
   1.292 +				$needToAppend = FALSE;
   1.293 +	   			}
   1.294 +			push( @outLines, $sLine );
   1.295 +			push( @outLines, "\n" );
   1.296 +	   		}
   1.297 +	   	if ( $needToAppend eq FALSE )
   1.298 +	   	   	{
   1.299 +	   	   	print "Writing new settings into epoc.ini\n";
   1.300 +	   	   	# we have read the entire file and replaced what we need to
   1.301 +	   	   	# now lets write it back to the file
   1.302 +		   	seek( EPOCINI, 0, 0 );
   1.303 +	   	   	print EPOCINI @outLines;
   1.304 +	   	   	$finished = TRUE;
   1.305 +           	}
   1.306 +        close ( EPOCINI );
   1.307 +		}
   1.308 +
   1.309 +	if ( $finished eq FALSE )
   1.310 +	    {
   1.311 +       	if ( ($needToAppend eq TRUE) && ($epocIniAlreadyExists eq TRUE) )
   1.312 +       	    {
   1.313 +       	    print "Appending settings to current epoc.ini\n";
   1.314 +       	  	# we must append all the settings onto the end of the current epoc.ini
   1.315 +	   	  	open( EPOCINI, ">>$drive\\$epocroot\\epoc32\\data\\epoc.ini" ) or die "Can't open epoc.ini!\n";
   1.316 +       	  	}
   1.317 +    	elsif ( $epocIniAlreadyExists eq FALSE )
   1.318 +       	 	{
   1.319 +       	 	print "Creating new epoc.ini\n";
   1.320 +       	  	# create new file
   1.321 +	   	  	open( EPOCINI, ">$drive\\$epocroot\\epoc32\\data\\epoc.ini" );
   1.322 +       	  	}
   1.323 +
   1.324 +		print EPOCINI "\nETHER_NIF=";
   1.325 +	   	print EPOCINI "$etherNif\n";
   1.326 +	   	print EPOCINI "ETHER_MAC=";
   1.327 +	   	print EPOCINI "$etherMac\n";
   1.328 +	   	print EPOCINI "ETHER_SPEED=";
   1.329 +	   	print EPOCINI "$etherSpeed\n";
   1.330 +	   	close ( EPOCINI );
   1.331 +     	}
   1.332 +}
   1.333 +
   1.334 +
   1.335 +
   1.336 +
   1.337 +