sl@0: # sl@0: # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of the License "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # This script is designed to provide a working ethernet setup sl@0: # for EKA1 or EKA2. It works by running Netcards.exe sl@0: # then taking the output from Netcards (ethernet.ini) sl@0: # and appending the ethernet settings to epoc.ini for EKA2 sl@0: # or creating ethermac.dat and etherdriver.dat for EKA1 sl@0: # The script can sl@0: # - create a working ethernet setup with "ethernet" config option sl@0: # - restore previous setup with "restore" config option sl@0: # Please note: The script assumes that target wins is running on EKA1 sl@0: # Copied from configchange.pl to make use of environment varible for mac address sl@0: # Copied from configchangebats.pl to adapt for multiple network cards in "Blade" type servers. sl@0: # sl@0: sl@0: use Getopt::Long; sl@0: use Cwd; sl@0: sl@0: use Getopt::Long; sl@0: use Cwd; sl@0: sl@0: my $config="default"; sl@0: my $target="default"; sl@0: my $kernel="default"; sl@0: my $showhelp='0'; sl@0: sl@0: my $etherNif; sl@0: my $etherMac = $ENV{'WINSCW_MAC'}; sl@0: my $etherSpeed; sl@0: sl@0: # this variable is passed as an argument to netcards.exe sl@0: # specifies which interface to use in case of multiple interfaces sl@0: sl@0: my $interface=0; sl@0: sl@0: $/ = "\n"; sl@0: sl@0: GetOptions('config=s' => \$config, 'kernel=s' => \$kernel, 'target=s' => \$target, 'variant=s' => \$variant, 'help' => \$showhelp, 'interface:i' => \$interface); sl@0: sl@0: $config = lc( $config ); sl@0: $kernel = lc( $kernel ); sl@0: $target = lc( $target ); sl@0: $variant = lc( $variant ); sl@0: sl@0: sl@0: sl@0: if( $showhelp || ( $kernel ne "eka1" && $kernel ne "eka2" ) || sl@0: ( $target ne "wins" && $target ne "winscw" ) || sl@0: ( $config ne "ethernetwithcommdb" && $config ne "restorecommdb" && $config ne "ethernetnocommdb" ) || sl@0: ( $variant ne "udeb" && $variant ne "urel" ) ) sl@0: { sl@0: print "Command usage: configchange --config [ethernetWithCommDB|restoreCommDB|ethernetNoCommDB] --kernel [EKA1|EKA2] --target [wins|winscw] --variant [UDEB|UREL]\n"; sl@0: print "\t\t--config \tSelect required configuration\n"; sl@0: print "\t\t--kernel \tKernel variant\n"; sl@0: print "\t\t--target \tTarget emulator\n"; sl@0: print "\t\t--variant \tBuild type\n"; sl@0: print "\t\t--interface \tInterface Number\n"; sl@0: print "\t\t--help \tThis text\n"; sl@0: exit 0; sl@0: } sl@0: sl@0: my $epocroot = &getEpocroot; sl@0: my $drive = &getDrive; sl@0: sl@0: if($ENV{'SERVER_TYPE'} && $ENV{'SERVER_TYPE'} =~ /blade/i){ sl@0: $interface=1; sl@0: } sl@0: sl@0: sl@0: my $netIF = ""; sl@0: my $netConfigOutput = `net config rdr`; sl@0: sl@0: # Sample output: sl@0: #J:\epoc32\winscw\c>net config rdr sl@0: #Computer name \\SYWINPAP0005 sl@0: #Full Computer name SYWINPAP0005.prod.ad.symbian.intra sl@0: #User name extkesavanathimoolam sl@0: # sl@0: #Workstation active on sl@0: # NetbiosSmb (000000000000) sl@0: # NetBT_Tcpip_{0B887A6F-A34C-4A43-85A4-FA5D58BEEE8A} (00215E2CB2F6) sl@0: sl@0: sl@0: # capture the network-interface info to compare it later with netcards output sl@0: if($netConfigOutput =~ /NetBT_Tcpip_\{(.*)?\}/i){ sl@0: $netIF = $1; sl@0: } sl@0: sl@0: sl@0: # netcards output sample sl@0: #J:\epoc32\winscw\c>\epoc32\tools\netcards.exe 1 sl@0: #Adapters installed: sl@0: #N/A - \Device\NPF_GenericDialupAdapter sl@0: # Adapter for generic dialup and VPN capture sl@0: # sl@0: # 1 - \Device\NPF_{0B887A6F-A34C-4A43-85A4-FA5D58BEEE8A} sl@0: # Broadcom Advanced Server Program Driver for Windows Server 2003 with SNP sl@0: # sl@0: # sl@0: # 2 - \Device\NPF_{11F02767-7BDE-49FF-87F2-FD7F46FA8C60} sl@0: # Broadcom L2 NDIS client driver sl@0: # sl@0: # 3 - \Device\NPF_{9672396E-2361-42BF-80CF-1E03AF7BD59F} sl@0: # Broadcom L2 NDIS client driver sl@0: # sl@0: #Using adapter 1 sl@0: #Physical address read: 00:21:5e:2c:b2:f6 sl@0: #Writing settings to ethernet.ini. sl@0: sl@0: sl@0: $netCardsCommand = "$drive\\$epocroot\\epoc32\\tools\\netcards $interface"; sl@0: foreach (split("\n",`$netCardsCommand`)){ sl@0: if(/\s*(\d)\s+\-\s+.*?$netIF/){ sl@0: $interface = $1; sl@0: last; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: if( $config ne "restorecommdb" ) sl@0: { sl@0: # must be creating some ethernet setup sl@0: if( $config eq "ethernetwithcommdb" ) sl@0: { sl@0: # write an appropriate commDB setup sl@0: print( "Setting up CommDB for ethernet\n" ); sl@0: system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ceddump" ) == 0 sl@0: or die "Error running ceddump!\n"; sl@0: system( "move $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" ) == 0 sl@0: or die "Failed to rename cedout.cfg!\n"; sl@0: system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -dtextshell -- -i c:\\EthernetCed.xml") == 0 sl@0: or die "Error running ced!\n"; sl@0: } sl@0: print( "Running Netcards to obtain adapter info\n" ); sl@0: system( "$drive\\$epocroot\\epoc32\\tools\\netcards $interface" ) == 0 sl@0: or die "Error running netcards!\n"; sl@0: sl@0: 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: sl@0: if ($kernel eq "eka1") sl@0: { sl@0: 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: } sl@0: sl@0: while( ) sl@0: { sl@0: chomp; sl@0: my $sLine = $_; sl@0: sl@0: if( $sLine =~ /ETHER_NIF=(.*)/i ) sl@0: { sl@0: #print "Matched ETHER_NIF\n"; sl@0: if ($kernel eq "eka1") sl@0: { sl@0: print ETHERDRV "$1"; sl@0: } sl@0: else sl@0: { sl@0: $etherNif = $1; sl@0: } sl@0: } sl@0: elsif( $sLine =~ /ETHER_SPEED=(.*)/i ) sl@0: { sl@0: #print "Matched ETHER_SPEED\n"; sl@0: if ($kernel eq "eka2") sl@0: { sl@0: $etherSpeed = $1; sl@0: } sl@0: } sl@0: #print "line: $sLine\n"; sl@0: } sl@0: if ($kernel eq "eka1") sl@0: { sl@0: close( ETHERDRV ); sl@0: } sl@0: else sl@0: { sl@0: # do the insertion to epoc.ini sl@0: &generateEpocIni; sl@0: } sl@0: close( INFILE ); sl@0: } sl@0: else sl@0: { sl@0: if( -f "$drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg" ) sl@0: { sl@0: system( "$drive\\$epocroot\\epoc32\\release\\$target\\$variant\\ced -i c:\\nonethernetced.cfg" ) == 0 sl@0: or die "Can't find backup ced file!\n"; sl@0: system( "move $drive\\$epocroot\\epoc32\\$target\\c\\nonethernetced.cfg $drive\\$epocroot\\epoc32\\$target\\c\\cedout.cfg" ) == 0 sl@0: or die "Can't rename backup ced file!\n"; sl@0: } sl@0: else sl@0: { sl@0: print "No restore file found!\n"; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: # sl@0: # Determines, validates, and returns EPOCROOT. sl@0: # sl@0: sub getEpocroot sl@0: { sl@0: my $epocroot = $ENV{EPOCROOT}; sl@0: die "ERROR: Must set the EPOCROOT environment variable.\n" sl@0: if (!defined($epocroot)); sl@0: $epocroot =~ s-/-\\-go; # for those working with UNIX shells sl@0: die "ERROR: EPOCROOT must be an absolute path, " . sl@0: "not containing a drive letter.\n" if ($epocroot !~ /^\\/); sl@0: die "ERROR: EPOCROOT must not be a UNC path.\n" if ($epocroot =~ /^\\\\/); sl@0: die "ERROR: EPOCROOT must end with a backslash.\n" if ($epocroot !~ /\\$/); sl@0: die "ERROR: EPOCROOT must specify an existing directory.\n" sl@0: if (!-d $epocroot); sl@0: return $epocroot; sl@0: } sl@0: sl@0: # sl@0: # Determines and returns the current drive, if any. sl@0: # sl@0: sub getDrive sl@0: { sl@0: my $wd = cwd; sl@0: my $drive; sl@0: if($wd =~ /^([a-zA-Z]:)/) { sl@0: $drive = $1; sl@0: } else { sl@0: # Perhaps we're on a machine that has no drives. sl@0: $drive = ""; sl@0: } sl@0: return $drive; sl@0: } sl@0: sl@0: # sl@0: # sl@0: # sl@0: sub generateEpocIni sl@0: { sl@0: my @outLines; sl@0: my $length = 0; sl@0: my $needToAppend = TRUE; sl@0: my $epocIniAlreadyExists = FALSE; sl@0: my $finished = FALSE; sl@0: print "generating epoc ini\n"; sl@0: if ( -e "$drive\\$epocroot\\epoc32\\data\\epoc.ini" ) sl@0: { sl@0: $epocIniAlreadyExists = TRUE; sl@0: open( EPOCINI, "+<$drive\\$epocroot\\epoc32\\data\\epoc.ini" ); sl@0: seek( EPOCINI, 0, 0 ); sl@0: while( ) sl@0: { sl@0: chomp; sl@0: my $sLine = $_; sl@0: if( $sLine =~ /ETHER_NIF=(.*)/i ) sl@0: { sl@0: #print "matched etherNIF\n"; sl@0: $length = length( $etherNif ); sl@0: sl@0: substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherNif; sl@0: $needToAppend = FALSE; sl@0: } sl@0: elsif( $sLine =~ /ETHER_MAC=(.*)/i ) sl@0: { sl@0: print "Matched ETHER_MAC\n"; sl@0: $length = length( $etherMac ); sl@0: substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherMac; sl@0: $needToAppend = FALSE; sl@0: } sl@0: elsif( $sLine =~ /ETHER_SPEED=(.*)/i ) sl@0: { sl@0: #print "Matched etherSpeed\n"; sl@0: $length = length( $etherSpeed ); sl@0: substr( $sLine, (index( $sLine, "=" )+1), $length ) = $etherSpeed; sl@0: $needToAppend = FALSE; sl@0: } sl@0: push( @outLines, $sLine ); sl@0: push( @outLines, "\n" ); sl@0: } sl@0: if ( $needToAppend eq FALSE ) sl@0: { sl@0: print "Writing new settings into epoc.ini\n"; sl@0: # we have read the entire file and replaced what we need to sl@0: # now lets write it back to the file sl@0: seek( EPOCINI, 0, 0 ); sl@0: print EPOCINI @outLines; sl@0: $finished = TRUE; sl@0: } sl@0: close ( EPOCINI ); sl@0: } sl@0: sl@0: if ( $finished eq FALSE ) sl@0: { sl@0: if ( ($needToAppend eq TRUE) && ($epocIniAlreadyExists eq TRUE) ) sl@0: { sl@0: print "Appending settings to current epoc.ini\n"; sl@0: # we must append all the settings onto the end of the current epoc.ini sl@0: open( EPOCINI, ">>$drive\\$epocroot\\epoc32\\data\\epoc.ini" ) or die "Can't open epoc.ini!\n"; sl@0: } sl@0: elsif ( $epocIniAlreadyExists eq FALSE ) sl@0: { sl@0: print "Creating new epoc.ini\n"; sl@0: # create new file sl@0: open( EPOCINI, ">$drive\\$epocroot\\epoc32\\data\\epoc.ini" ); sl@0: } sl@0: sl@0: print EPOCINI "\nETHER_NIF="; sl@0: print EPOCINI "$etherNif\n"; sl@0: print EPOCINI "ETHER_MAC="; sl@0: print EPOCINI "$etherMac\n"; sl@0: print EPOCINI "ETHER_SPEED="; sl@0: print EPOCINI "$etherSpeed\n"; sl@0: close ( EPOCINI ); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: