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