6 |
use warnings; |
use warnings; |
7 |
use SOAP::Lite; |
use SOAP::Lite; |
8 |
#use SOAP::Lite +trace => 'all'; |
#use SOAP::Lite +trace => 'all'; |
9 |
|
use Data::Dump qw/dump/; |
10 |
|
|
11 |
|
use lib 'lib'; |
12 |
|
|
13 |
my $amt_host = $ENV{'AMT_HOST'}; |
my $amt_host = $ENV{'AMT_HOST'}; |
14 |
my $amt_port = "16992"; |
my $amt_port = "16992"; |
23 |
# data |
# data |
24 |
|
|
25 |
my @ps = ("S0", "S1", "S2", "S3", "S4", "S5 (soft-off)", "S4/S5", "Off"); |
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, |
|
|
); |
|
26 |
|
|
27 |
# incomplete list |
# incomplete list |
28 |
my %pt_status = ( |
my %pt_status = ( |
79 |
return $main::amt_user => $main::amt_pass; |
return $main::amt_user => $main::amt_pass; |
80 |
} |
} |
81 |
|
|
82 |
sub soap_init() { |
sub init() { |
83 |
my $proxybase = "http://$amt_host:$amt_port"; |
my $proxybase = "http://$amt_host:$amt_port"; |
84 |
my $schemabase = "http://schemas.intel.com/platform/client"; |
my $schemabase = "http://schemas.intel.com/platform/client"; |
85 |
|
|
97 |
$sas->autotype(0); |
$sas->autotype(0); |
98 |
$rcs->autotype(0); |
$rcs->autotype(0); |
99 |
|
|
100 |
|
warn $proxybase; |
101 |
|
|
102 |
$amt_version = $sas->GetCoreVersion()->paramsout; |
$amt_version = $sas->GetCoreVersion()->paramsout; |
103 |
} |
} |
104 |
|
|
135 |
|
|
136 |
if (!defined($rc)) { |
if (!defined($rc)) { |
137 |
$msg = "soap failure"; |
$msg = "soap failure"; |
138 |
|
warn dump( $ret->faultdetail ); |
139 |
} elsif (!defined($pt_status{$rc})) { |
} elsif (!defined($pt_status{$rc})) { |
140 |
$msg = sprintf("unknown pt_status code: 0x%x", $rc); |
$msg = sprintf("unknown pt_status code: 0x%x", $rc); |
141 |
} else { |
} else { |
223 |
my $powerstate = $rcs->GetSystemPowerState()->paramsout; |
my $powerstate = $rcs->GetSystemPowerState()->paramsout; |
224 |
printf "Powerstate: %s\n", $ps [ $powerstate & 0x0f ]; |
printf "Powerstate: %s\n", $ps [ $powerstate & 0x0f ]; |
225 |
} |
} |
226 |
|
|
227 |
sub print_remote_info() { |
use Intel::AMT::RemoteControl; |
228 |
|
|
229 |
|
sub describe { |
230 |
|
warn 'describe ',dump( @_ ) if $amt_debug; |
231 |
|
my ( $value, $map ) = @_; |
232 |
|
my $out; |
233 |
|
foreach my $name ( keys %$map ) { |
234 |
|
push @$out, $name if $value & $map->{$name}; |
235 |
|
} |
236 |
|
push @$out, sprintf("%x", $value) unless $out; |
237 |
|
return $out; |
238 |
|
} |
239 |
|
|
240 |
|
sub RemoteControlCapabilities { |
241 |
my @rccaps = $rcs->GetRemoteControlCapabilities()->paramsout; |
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 " : ""; |
|
242 |
|
|
243 |
printf " SystemFirmwareCapabilities %x\n", $rccaps[4]; |
my $return = { |
244 |
|
IanaOemNumber => $rccaps[0], |
245 |
|
OemDefinedCapabilities => |
246 |
|
describe( $rccaps[1], $Intel::AMT::RemoteControl::OemDefinedCapabilitiesSupported ), |
247 |
|
SpecialCommand => |
248 |
|
describe( $rccaps[2], $Intel::AMT::RemoteControl::SpecialCommandSupported ), |
249 |
|
SystemCapabilities => |
250 |
|
describe( $rccaps[3], $Intel::AMT::RemoteControl::SystemCapabilitiesSupported ), |
251 |
|
SystemFirmwareCapabilities => |
252 |
|
describe( $rccaps[4], $Intel::AMT::RemoteControl::SystemFirmwareCapabilitiesSupported ), |
253 |
|
}; |
254 |
|
|
255 |
|
warn '# RemoteControlCapabilities ',dump( $return ); |
256 |
|
return $return; |
257 |
|
} |
258 |
|
|
259 |
|
sub RemoteControl { |
260 |
|
my @args; |
261 |
|
|
262 |
|
my $hostname = $nas->GetHostName()->paramsout; |
263 |
|
my $domainname = $nas->GetDomainName()->paramsout; |
264 |
|
|
265 |
|
warn $hostname, '.', $domainname, ' execute: ', dump( @_ ); |
266 |
|
|
267 |
|
my $BootOptions; |
268 |
|
my $SpecialCommandParameter; |
269 |
|
|
270 |
|
foreach my $command ( @_ ) { |
271 |
|
|
272 |
|
my $i; |
273 |
|
|
274 |
|
if ( $i = $Intel::AMT::RemoteControl::BootOptions->{$command} ) { |
275 |
|
if ( $BootOptions ) { |
276 |
|
$BootOptions |= $i; |
277 |
|
next; |
278 |
|
} else { |
279 |
|
$BootOptions = $i; |
280 |
|
$command = 'SetBootOptions'; |
281 |
|
} |
282 |
|
} elsif ( $i = $Intel::AMT::RemoteControl::SpecialCommandParameters->{$command} ) { |
283 |
|
$SpecialCommandParameter |= $i; |
284 |
|
} elsif ( $i = $Intel::AMT::RemoteControl::RemoteControlCommand->{$command} ) { |
285 |
|
push @args, SOAP::Data->name( 'Command' => $i ); |
286 |
|
} elsif ( $i = $Intel::AMT::RemoteControl::SpecialCommand->{$command} ) { |
287 |
|
push @args, SOAP::Data->name( 'SpecialCommand' => $i ); |
288 |
|
} elsif ( $i = $Intel::AMT::RemoteControl::OEMParameters->{$command} ) { |
289 |
|
push @args, SOAP::Data->name( 'OEMParameters' => $i ); |
290 |
|
} else { |
291 |
|
die "can't find $command"; |
292 |
|
} |
293 |
|
|
294 |
|
} |
295 |
|
|
296 |
|
|
297 |
|
if ( $BootOptions ) { |
298 |
|
warn "invalid BootOptions $BootOptions" unless |
299 |
|
( $BootOptions & $Intel::AMT::RemoteControl::BootOptionsReservedBits ); |
300 |
|
push @args, SOAP::Data->name( 'BootOptions' => $BootOptions ); |
301 |
|
} |
302 |
|
|
303 |
|
if ( $SpecialCommandParameter ) { |
304 |
|
warn "invalid SpecialCommandParameter $SpecialCommandParameter" unless |
305 |
|
( $SpecialCommandParameter & $Intel::AMT::RemoteControl::SpecialCommandParametersReservedBits ); |
306 |
|
push @args, SOAP::Data->name( 'SpecialCommandParameter' => $SpecialCommandParameter ); |
307 |
|
} |
308 |
|
|
309 |
|
push @args, SOAP::Data->name( 'IanaOemNumber' => $Intel::AMT::RemoteControl::IanaNumbers->{IntelIanaNumber} ); |
310 |
|
warn "args ",dump( @args ); |
311 |
|
|
312 |
|
do_soap($rcs, "RemoteControl", @args); |
313 |
} |
} |
314 |
|
|
315 |
sub print_network_info() { |
sub print_network_info() { |
327 |
} |
} |
328 |
} |
} |
329 |
|
|
|
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"; |
|
|
} |
|
|
} |
|
|
|
|
330 |
sub ipv4_addr($$) { |
sub ipv4_addr($$) { |
331 |
my $name = shift; |
my $name = shift; |
332 |
my $ipv4 = shift; |
my $ipv4 = shift; |
394 |
sub command { |
sub command { |
395 |
my ($amt_command,$amt_arg) = @_; |
my ($amt_command,$amt_arg) = @_; |
396 |
|
|
397 |
soap_init; |
init; |
398 |
|
|
399 |
if ($amt_command eq "info") { |
if ($amt_command eq "info") { |
400 |
print_general_info; |
print_general_info; |
401 |
print_remote_info; |
RemoteControlCapabilities; |
402 |
} elsif ($amt_command eq "netinfo") { |
} elsif ($amt_command eq "netinfo") { |
403 |
check_amt_version(2,5); |
check_amt_version(2,5); |
404 |
print_network_info; |
print_network_info; |
405 |
} elsif ($amt_command eq "netconf") { |
} elsif ($amt_command eq "netconf") { |
406 |
check_amt_version(2,5); |
check_amt_version(2,5); |
407 |
configure_network(@ARGV); |
configure_network(@_); |
408 |
} elsif ($amt_command =~ m/^(reset|powerup|powerdown|powercycle)$/) { |
} elsif ($amt_command =~ m/^(reset|powerup|powerdown|powercycle)$/) { |
409 |
remote_control($amt_command, $amt_arg); |
remote_control($amt_command, $amt_arg); |
410 |
} else { |
} else { |
415 |
|
|
416 |
warn 'loaded'; |
warn 'loaded'; |
417 |
|
|
418 |
|
warn 'init ', init; |
419 |
|
|
420 |
1; |
1; |