--- trunk/lib/Intel/AMT/SOAP.pm 2009/08/08 15:07:39 2 +++ trunk/lib/Intel/AMT/SOAP.pm 2009/08/08 20:38:06 5 @@ -6,6 +6,9 @@ use warnings; use SOAP::Lite; #use SOAP::Lite +trace => 'all'; +use Data::Dump qw/dump/; + +use lib 'lib'; my $amt_host = $ENV{'AMT_HOST'}; my $amt_port = "16992"; @@ -20,24 +23,6 @@ # data my @ps = ("S0", "S1", "S2", "S3", "S4", "S5 (soft-off)", "S4/S5", "Off"); -my %rcc = ( - "reset" => "16", - "powerup" => "17", - "powerdown" => "18", - "powercycle" => "19", -); - -my %rccs = ( - "nop" => "0", - "pxe" => "1", - "hd" => "2", - "hdsafe" => "3", - "diag" => "4", - "cd" => "5", -); -my %rccs_oem = ( - "bios" => 0xc1, -); # incomplete list my %pt_status = ( @@ -94,7 +79,7 @@ return $main::amt_user => $main::amt_pass; } -sub soap_init() { +sub init() { my $proxybase = "http://$amt_host:$amt_port"; my $schemabase = "http://schemas.intel.com/platform/client"; @@ -112,6 +97,8 @@ $sas->autotype(0); $rcs->autotype(0); + warn $proxybase; + $amt_version = $sas->GetCoreVersion()->paramsout; } @@ -148,6 +135,7 @@ if (!defined($rc)) { $msg = "soap failure"; +warn dump( $ret->faultdetail ); } elsif (!defined($pt_status{$rc})) { $msg = sprintf("unknown pt_status code: 0x%x", $rc); } else { @@ -235,32 +223,93 @@ my $powerstate = $rcs->GetSystemPowerState()->paramsout; printf "Powerstate: %s\n", $ps [ $powerstate & 0x0f ]; } - -sub print_remote_info() { + +use Intel::AMT::RemoteControl; + +sub describe { + warn 'describe ',dump( @_ ) if $amt_debug; + my ( $value, $map ) = @_; + my $out; + foreach my $name ( keys %$map ) { + push @$out, $name if $value & $map->{$name}; + } + push @$out, sprintf("%x", $value) unless $out; + return $out; +} + +sub RemoteControlCapabilities { my @rccaps = $rcs->GetRemoteControlCapabilities()->paramsout; - printf "Remote Control Capabilities:\n"; - printf " IanaOemNumber %x\n", $rccaps[0]; - printf " OemDefinedCapabilities %s%s%s%s%s\n", - $rccaps[1] & 0x01 ? "IDER " : "", - $rccaps[1] & 0x02 ? "SOL " : "", - $rccaps[1] & 0x04 ? "BiosReflash " : "", - $rccaps[1] & 0x08 ? "BiosSetup " : "", - $rccaps[1] & 0x10 ? "BiosPause " : ""; - - printf " SpecialCommandsSupported %s%s%s%s%s\n", - $rccaps[2] & 0x0100 ? "PXE-boot " : "", - $rccaps[2] & 0x0200 ? "HD-boot " : "", - $rccaps[2] & 0x0400 ? "HD-boot-safemode " : "", - $rccaps[2] & 0x0800 ? "diag-boot " : "", - $rccaps[2] & 0x1000 ? "cd-boot " : ""; - - printf " SystemCapabilitiesSupported %s%s%s%s\n", - $rccaps[3] & 0x01 ? "powercycle " : "", - $rccaps[3] & 0x02 ? "powerdown " : "", - $rccaps[3] & 0x03 ? "powerup " : "", - $rccaps[3] & 0x04 ? "reset " : ""; - printf " SystemFirmwareCapabilities %x\n", $rccaps[4]; + my $return = { + IanaOemNumber => $rccaps[0], + OemDefinedCapabilities => + describe( $rccaps[1], $Intel::AMT::RemoteControl::OemDefinedCapabilitiesSupported ), + SpecialCommand => + describe( $rccaps[2], $Intel::AMT::RemoteControl::SpecialCommandSupported ), + SystemCapabilities => + describe( $rccaps[3], $Intel::AMT::RemoteControl::SystemCapabilitiesSupported ), + SystemFirmwareCapabilities => + describe( $rccaps[4], $Intel::AMT::RemoteControl::SystemFirmwareCapabilitiesSupported ), + }; + + warn '# RemoteControlCapabilities ',dump( $return ); + return $return; +} + +sub RemoteControl { + my @args; + + my $hostname = $nas->GetHostName()->paramsout; + my $domainname = $nas->GetDomainName()->paramsout; + + warn $hostname, '.', $domainname, ' execute: ', dump( @_ ); + + my $BootOptions; + my $SpecialCommandParameter; + + foreach my $command ( @_ ) { + + my $i; + + if ( $i = $Intel::AMT::RemoteControl::BootOptions->{$command} ) { + if ( $BootOptions ) { + $BootOptions |= $i; + next; + } else { + $BootOptions = $i; + $command = 'SetBootOptions'; + } + } elsif ( $i = $Intel::AMT::RemoteControl::SpecialCommandParameters->{$command} ) { + $SpecialCommandParameter |= $i; + } elsif ( $i = $Intel::AMT::RemoteControl::RemoteControlCommand->{$command} ) { + push @args, SOAP::Data->name( 'Command' => $i ); + } elsif ( $i = $Intel::AMT::RemoteControl::SpecialCommand->{$command} ) { + push @args, SOAP::Data->name( 'SpecialCommand' => $i ); + } elsif ( $i = $Intel::AMT::RemoteControl::OEMParameters->{$command} ) { + push @args, SOAP::Data->name( 'OEMParameters' => $i ); + } else { + die "can't find $command"; + } + + } + + + if ( $BootOptions ) { + warn "invalid BootOptions $BootOptions" unless + ( $BootOptions & $Intel::AMT::RemoteControl::BootOptionsReservedBits ); + push @args, SOAP::Data->name( 'BootOptions' => $BootOptions ); + } + + if ( $SpecialCommandParameter ) { + warn "invalid SpecialCommandParameter $SpecialCommandParameter" unless + ( $SpecialCommandParameter & $Intel::AMT::RemoteControl::SpecialCommandParametersReservedBits ); + push @args, SOAP::Data->name( 'SpecialCommandParameter' => $SpecialCommandParameter ); + } + + push @args, SOAP::Data->name( 'IanaOemNumber' => $Intel::AMT::RemoteControl::IanaNumbers->{IntelIanaNumber} ); + warn "args ",dump( @args ); + + do_soap($rcs, "RemoteControl", @args); } sub print_network_info() { @@ -278,34 +327,6 @@ } } -sub remote_control($$) { - my $command = shift; - my $special = shift; - my @args; - - my $hostname = $nas->GetHostName()->paramsout; - my $domainname = $nas->GetDomainName()->paramsout; - printf "host %s.%s, %s [y/N] ? ", $hostname, $domainname, $command; - my $reply = <>; - if ($reply =~ m/^(y|yes)$/i) { - printf "execute: %s\n", $command; - push (@args, SOAP::Data->name('Command' => $rcc{$command})); - push (@args, SOAP::Data->name('IanaOemNumber' => 343)); - if (defined($special) && defined($rccs{$special})) { - push (@args, SOAP::Data->name('SpecialCommand' - => $rccs{$special} )); - } - if (defined($special) && defined($rccs_oem{$special})) { - push (@args, SOAP::Data->name('OEMparameters' => 1 )); - push (@args, SOAP::Data->name('SpecialCommand' - => $rccs_oem{$special} )); - } - do_soap($rcs, "RemoteControl", @args); - } else { - printf "canceled\n"; - } -} - sub ipv4_addr($$) { my $name = shift; my $ipv4 = shift; @@ -373,17 +394,17 @@ sub command { my ($amt_command,$amt_arg) = @_; - soap_init; + init; if ($amt_command eq "info") { print_general_info; - print_remote_info; + RemoteControlCapabilities; } elsif ($amt_command eq "netinfo") { check_amt_version(2,5); print_network_info; } elsif ($amt_command eq "netconf") { check_amt_version(2,5); - configure_network(@ARGV); + configure_network(@_); } elsif ($amt_command =~ m/^(reset|powerup|powerdown|powercycle)$/) { remote_control($amt_command, $amt_arg); } else { @@ -394,4 +415,6 @@ warn 'loaded'; +warn 'init ', init; + 1;