]>
git.zerfleddert.de Git - amt/blob - amttool
69bd1bb84b39a39dc4e4589c744d309336154cc5
5 #use SOAP::Lite +trace => 'all';
8 my $amt_port = "16992";
9 $main::amt_user
= "admin";
10 $main::amt_pass
= $ENV{'AMT_PASSWORD'};
12 $amt_debug = $ENV{'AMT_DEBUG'} if defined($ENV{'AMT_DEBUG'});
14 my $amt_command = shift;
15 $amt_command = "info" if !defined($amt_command);
19 #############################################################################
22 my @ps = ("S0", "S1", "S2", "S3", "S4", "S5 (soft-off)", "S4/S5", "Off");
33 0x1 => "internal error",
34 0x3 => "invalid pt_mode",
35 0xc => "invalid name",
36 0xf => "invalid byte_count",
37 0x10 => "not permitted",
38 0x17 => "max limit_reached",
39 0x18 => "invalid auth_type",
40 0x1a => "invalid dhcp_mode",
41 0x1b => "invalid ip_address",
42 0x1c => "invalid domain_name",
43 0x20 => "invalid provisioning_state",
44 0x22 => "invalid time",
45 0x23 => "invalid index",
46 0x24 => "invalid parameter",
47 0x25 => "invalid netmask",
48 0x26 => "flash write_limit_exceeded",
49 0x800 => "network if_error_base",
50 0x801 => "unsupported oem_number",
51 0x802 => "unsupported boot_option",
52 0x803 => "invalid command",
53 0x804 => "invalid special_command",
54 0x805 => "invalid handle",
55 0x806 => "invalid password",
56 0x807 => "invalid realm",
57 0x808 => "storage acl_entry_in_use",
58 0x809 => "data missing",
60 0x80b => "eventlog frozen",
61 0x80c => "pki missing_keys",
62 0x80d => "pki generating_keys",
63 0x80e => "invalid key",
64 0x80f => "invalid cert",
65 0x810 => "cert key_not_match",
66 0x811 => "max kerb_domain_reached",
67 0x812 => "unsupported",
68 0x813 => "invalid priority",
70 0x815 => "invalid credentials",
71 0x816 => "invalid passphrase",
72 0x818 => "no association",
76 #############################################################################
79 my ($nas, $sas, $rcs);
81 sub SOAP
::Transport
::HTTP
::Client
::get_basic_credentials
{
82 return $main::amt_user
=> $main::amt_pass
;
86 my $proxybase = "http://$amt_host:$amt_port";
87 my $schemabase = "http://schemas.intel.com/platform/client";
89 $nas = SOAP
::Lite
->new(
90 proxy
=> "$proxybase/NetworkAdministrationService",
91 default_ns
=> "$schemabase/NetworkAdministration/2004/01");
92 $sas = SOAP
::Lite
->new(
93 proxy
=> "$proxybase/SecurityAdministrationService",
94 default_ns
=> "$schemabase/SecurityAdministration/2004/01");
95 $rcs = SOAP
::Lite
->new(
96 proxy
=> "$proxybase/RemoteControlService",
97 default_ns
=> "$schemabase/RemoteControl/2004/01");
103 $amt_version = $sas->GetCoreVersion()->paramsout;
107 #############################################################################
113 This utility can talk to Intel AMT managed machines.
115 usage: amttool <hostname> [ <command> ]
117 info - print some machine info (default).
118 reset - reset machine.
119 powerup - turn on machine.
120 powerdown - turn off machine.
121 powercycle - powercycle machine.
124 netinfo - print network config.
125 netconf <args> - configure network (check manpage).
127 Password is passed via AMT_PASSWORD environment variable.
132 sub print_result
($) {
134 my $rc = $ret->result;
138 $msg = "soap failure";
139 } elsif (!defined($pt_status{$rc})) {
140 $msg = sprintf("unknown pt_status code: 0x%x", $rc);
142 $msg = "pt_status: " . $pt_status{$rc};
144 printf "result: %s\n", $msg;
147 sub print_paramsout
($) {
149 my @paramsout = $ret->paramsout;
150 print "params: " . join(", ", @paramsout) . "\n";
158 foreach my $item (sort keys %{$hash}) {
159 if (ref($hash->{$item}) eq "HASH") {
160 # printf "%*s%s\n", $in, "", $item;
163 printf "%*s%-*s%s\n", $in, "", $wi, $item, $hash->{$item};
167 sub print_hash_ipv4
{
172 foreach my $item (sort keys %{$hash}) {
173 my $addr = sprintf("%d.%d.%d.%d",
174 $hash->{$item} / 256 / 256 / 256,
175 $hash->{$item} / 256 / 256 % 256,
176 $hash->{$item} / 256 % 256,
177 $hash->{$item} % 256);
178 printf "%*s%-*s%s\n", $in, "", $wi, $item, $addr;
188 $method = SOAP
::Data
->name($name)
189 ->attr( { xmlns
=> $soap->ns } );
193 open XML
, "| xmllint --format -";
194 print XML
$soap->serializer->envelope(method
=> $method, @_);
199 my $ret = $soap->call($method, @args);
204 sub check_amt_version
{
208 $amt_version =~ m/^(\d+).(\d+)/;
209 return if $1 > $major;
210 return if $1 == $major && $2 >= $minor;
211 die "version mismatch (need >= $major.$minor, have $amt_version)";
214 sub print_general_info
() {
215 printf "### AMT info on machine '%s' ###\n", $amt_host;
217 printf "AMT version: %s\n", $amt_version;
219 my $hostname = $nas->GetHostName()->paramsout;
220 my $domainname = $nas->GetDomainName()->paramsout;
221 printf "Hostname: %s.%s\n", $hostname, $domainname;
223 my $powerstate = $rcs->GetSystemPowerState()->paramsout;
224 printf "Powerstate: %s\n", $ps [ $powerstate & 0x0f ];
227 sub print_remote_info
() {
228 my @rccaps = $rcs->GetRemoteControlCapabilities()->paramsout;
229 printf "Remote Control Capabilities:\n";
230 printf " IanaOemNumber %x\n", $rccaps[0];
231 printf " OemDefinedCapabilities %s%s%s%s%s\n",
232 $rccaps[1] & 0x01 ?
"IDER " : "",
233 $rccaps[1] & 0x02 ?
"SOL " : "",
234 $rccaps[1] & 0x04 ?
"BiosReflash " : "",
235 $rccaps[1] & 0x08 ?
"BiosSetup " : "",
236 $rccaps[1] & 0x10 ?
"BiosPause " : "";
238 printf " SpecialCommandsSupported %s%s%s%s%s\n",
239 $rccaps[2] & 0x0100 ?
"PXE-boot " : "",
240 $rccaps[2] & 0x0200 ?
"HD-boot " : "",
241 $rccaps[2] & 0x0400 ?
"HD-boot-safemode " : "",
242 $rccaps[2] & 0x0800 ?
"diag-boot " : "",
243 $rccaps[2] & 0x1000 ?
"cd-boot " : "";
245 printf " SystemCapabilitiesSupported %s%s%s%s\n",
246 $rccaps[3] & 0x01 ?
"powercycle " : "",
247 $rccaps[3] & 0x02 ?
"powerdown " : "",
248 $rccaps[3] & 0x03 ?
"powerup " : "",
249 $rccaps[3] & 0x04 ?
"reset " : "";
251 printf " SystemFirmwareCapabilities %x\n", $rccaps[4];
254 sub print_network_info
() {
257 $ret = $nas->EnumerateInterfaces();
258 my @if = $ret->paramsout;
259 foreach my $if (@if) {
260 printf "Network Interface %s:\n", $if;
261 my $arg = SOAP
::Data
->name('InterfaceHandle' => $if);
262 $ret = $nas->GetInterfaceSettings($arg);
263 my $desc = $ret->paramsout;
264 print_hash
($ret->paramsout, 4, 32);
265 print_hash_ipv4
($ret->paramsout->{'IPv4Parameters'}, 8, 28);
269 sub remote_control
($) {
273 my $hostname = $nas->GetHostName()->paramsout;
274 my $domainname = $nas->GetDomainName()->paramsout;
275 printf "host %s.%s, %s [y/N] ? ", $hostname, $domainname, $command;
277 if ($reply =~ m/^(y|yes)$/i) {
278 printf "execute: %s\n", $command;
279 push (@args, SOAP
::Data
->name('Command' => $rcc{$command}));
280 push (@args, SOAP
::Data
->name('IanaOemNumber' => 343));
281 if ($command ne 'powerdown') {
282 push (@args, SOAP
::Data
->name('SpecialCommand' => 0xC1 ));
283 push (@args, SOAP
::Data
->name('SpecialCommandParameter' => 0));
284 push (@args, SOAP
::Data
->name('OEMparameters' => 1 ));
286 do_soap
($rcs, "RemoteControl", @args);
296 $ipv4 =~ m/(\d+).(\d+).(\d+).(\d+)/ or die "parse ipv4 address: $ipv4";
297 my $num = $1 * 256 * 256 * 256 +
301 printf STDERR
"ipv4 %-24s: %-16s -> %d\n", $name, $ipv4, $num
303 return SOAP
::Data
->name($name => $num);
306 sub configure_network
{
322 # build argument structs ...
323 die "no interface" if !defined($if);
324 die "no linkpolicy" if !defined($link);
326 $mode = "SEPARATE_MAC_ADDRESS";
327 die "no ip mask" if !defined($mask);
328 die "no default gw" if !defined($gw);
329 $dns1 = $gw if !defined($dns1);
330 $dns2 = "0.0.0.0" if !defined($dns2);
331 push (@ipv4, ipv4_addr
("LocalAddress", $ip));
332 push (@ipv4, ipv4_addr
("SubnetMask", $mask));
333 push (@ipv4, ipv4_addr
("DefaultGatewayAddress", $gw));
334 push (@ipv4, ipv4_addr
("PrimaryDnsAddress", $dns1));
335 push (@ipv4, ipv4_addr
("SecondaryDnsAddress", $dns2));
337 $mode = "SHARED_MAC_ADDRESS";
338 # no ip info -- use DHCP
341 push (@ifdesc, SOAP
::Data
->name("InterfaceMode" => $mode));
342 push (@ifdesc, SOAP
::Data
->name("LinkPolicy" => $link));
343 push (@ifdesc, SOAP
::Data
->name("IPv4Parameters" =>
344 \SOAP
::Data
->value(@ipv4)))
347 push (@args, SOAP
::Data
->name("InterfaceHandle" => $if));
348 push (@args, SOAP
::Data
->name("InterfaceDescriptor" =>
349 \SOAP
::Data
->value(@ifdesc)));
352 do_soap
($nas, "SetInterfaceSettings", @args);
356 #############################################################################
359 if (!defined($amt_host)) {
366 if ($amt_command eq "info") {
369 } elsif ($amt_command eq "netinfo") {
370 check_amt_version
(2,5);
372 } elsif ($amt_command eq "netconf") {
373 check_amt_version
(2,5);
374 configure_network
(@ARGV);
375 } elsif ($amt_command =~ m/^(reset|powerup|powerdown|powercycle)$/) {
376 remote_control
($amt_command);
378 print "unknown command: $amt_command\n";