summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkraxel <kraxel>2007-08-27 11:18:56 +0000
committerkraxel <kraxel>2007-08-27 11:18:56 +0000
commit5604c1ccf720c3ca2eba49693c95f58569bc788b (patch)
treeb10677bd673835e000ad90187713ae0177b43359
parentbb999fa11e4b6e63c00f0599386d9c34fa243b15 (diff)
downloadamtterm-5604c1ccf720c3ca2eba49693c95f58569bc788b.tar.gz
lots of amttool bits
-rwxr-xr-xamttool151
1 files changed, 142 insertions, 9 deletions
diff --git a/amttool b/amttool
index d6adfbc..de0fc26 100755
--- a/amttool
+++ b/amttool
@@ -8,10 +8,13 @@ my $amt_host = shift;
my $amt_port = "16992";
$main::amt_user = "admin";
$main::amt_pass = $ENV{'AMT_PASSWORD'};
+my $amt_debug = 1;
my $amt_command = shift;
$amt_command = "info" if !defined($amt_command);
+my $amt_version;
+
#############################################################################
# data
@@ -25,13 +28,47 @@ my %rcc = (
# incomplete list
my %pt_status = (
- 0x00 => "success",
- 0x01 => "internal error",
- 0x03 => "invalid pt mode",
- 0x0c => "invalid name",
- 0x0f => "invalid byte count",
- 0x10 => "not permitted",
- 0x17 => "max limit reached",
+ 0x0 => "success",
+ 0x1 => "internal error",
+ 0x3 => "invalid pt_mode",
+ 0xc => "invalid name",
+ 0xf => "invalid byte_count",
+ 0x10 => "not permitted",
+ 0x17 => "max limit_reached",
+ 0x18 => "invalid auth_type",
+ 0x1a => "invalid dhcp_mode",
+ 0x1b => "invalid ip_address",
+ 0x1c => "invalid domain_name",
+ 0x20 => "invalid provisioning_state",
+ 0x22 => "invalid time",
+ 0x23 => "invalid index",
+ 0x24 => "invalid parameter",
+ 0x25 => "invalid netmask",
+ 0x26 => "flash write_limit_exceeded",
+ 0x800 => "network if_error_base",
+ 0x801 => "unsupported oem_number",
+ 0x802 => "unsupported boot_option",
+ 0x803 => "invalid command",
+ 0x804 => "invalid special_command",
+ 0x805 => "invalid handle",
+ 0x806 => "invalid password",
+ 0x807 => "invalid realm",
+ 0x808 => "storage acl_entry_in_use",
+ 0x809 => "data missing",
+ 0x80a => "duplicate",
+ 0x80b => "eventlog frozen",
+ 0x80c => "pki missing_keys",
+ 0x80d => "pki generating_keys",
+ 0x80e => "invalid key",
+ 0x80f => "invalid cert",
+ 0x810 => "cert key_not_match",
+ 0x811 => "max kerb_domain_reached",
+ 0x812 => "unsupported",
+ 0x813 => "invalid priority",
+ 0x814 => "not found",
+ 0x815 => "invalid credentials",
+ 0x816 => "invalid passphrase",
+ 0x818 => "no association",
);
@@ -61,6 +98,8 @@ sub soap_init() {
$nas->autotype(0);
$sas->autotype(0);
$rcs->autotype(0);
+
+ $amt_version = $sas->GetCoreVersion()->paramsout;
}
@@ -93,7 +132,7 @@ sub print_result($) {
if (!defined($rc)) {
$msg = "soap failure";
} elsif (!defined($pt_status{$rc})) {
- $msg = "unknown pt_status code: " . $rc;
+ $msg = sprintf("unknown pt_status code: 0x%x", $rc);
} else {
$msg = "pt_status: " . $pt_status{$rc};
}
@@ -135,10 +174,30 @@ sub print_hash_ipv4 {
}
}
+sub dump_request {
+ my $soap = shift;
+ my $method = shift;
+
+ print "-- \n";
+ open XML, "| xmllint --format -";
+ print XML $soap->serializer->envelope(method => $method, @_);
+ close XML;
+ print "-- \n";
+}
+
+sub check_amt_version {
+ my $major = shift;
+ my $minor = shift;
+
+ $amt_version =~ m/^(\d+).(\d+)/;
+ return if $1 > $major;
+ return if $1 == $major && $2 >= $minor;
+ die "version mismatch (need >= $major.$minor, have $amt_version)";
+}
+
sub print_general_info() {
printf "### AMT info on machine '%s' ###\n", $amt_host;
- my $amt_version = $sas->GetCoreVersion()->paramsout;
printf "AMT version: %s\n", $amt_version;
my $hostname = $nas->GetHostName()->paramsout;
@@ -209,6 +268,75 @@ sub remote_control($) {
}
}
+sub ipv4_addr($$) {
+ my $name = shift;
+ my $ipv4 = shift;
+
+ $ipv4 =~ m/(\d+).(\d+).(\d+).(\d+)/ or die "parse ipv4 address: $ipv4";
+ my $num = $1 * 256 * 256 * 256 +
+ $2 * 256 * 246 +
+ $3 * 256 +
+ $4;
+ printf STDERR "ipv4 %-24s: %-16s -> %d\n", $name, $ipv4, $num
+ if $amt_debug;
+ return SOAP::Data->name($name => $num);
+}
+
+sub configure_network {
+ my $if = shift;
+ my $link = shift;
+ my $ip = shift;
+ my $mask = shift;
+ my $gw = shift;
+ my $dns1 = shift;
+ my $dns2 = shift;
+
+ my $mode;
+ my @ifdesc;
+ my @ipv4;
+
+ my $method;
+ my @args;
+
+ # build args ...
+ die "no interface" if !defined($if);
+ die "no linkpolicy" if !defined($link);
+ if (defined($ip)) {
+ $mode = "SEPARATE_MAC_ADDRESS";
+ die "no ip mask" if !defined($mask);
+ die "no default gw" if !defined($gw);
+ $dns1 = $gw if !defined($dns1);
+ $dns2 = "0.0.0.0" if !defined($dns2);
+ push (@ipv4, ipv4_addr("LocalAddress", $ip));
+ push (@ipv4, ipv4_addr("SubnetMask", $mask));
+ push (@ipv4, ipv4_addr("DefaultGatewayAddress", $gw));
+ push (@ipv4, ipv4_addr("PrimaryDnsAddress", $dns1));
+ push (@ipv4, ipv4_addr("SecondaryDnsAddress", $dns2));
+ } else {
+ $mode = "SHARED_MAC_ADDRESS";
+ # no ip info -- use DHCP
+ }
+
+ push (@ifdesc, SOAP::Data->name("InterfaceMode" => $mode));
+ push (@ifdesc, SOAP::Data->name("LinkPolicy" => $link));
+ push (@ifdesc, SOAP::Data->name("IPv4Parameters" =>
+ \SOAP::Data->value(@ipv4)))
+ if @ipv4;
+
+ # perform call
+ $method = SOAP::Data->name("SetInterfaceSettings")
+ ->attr( { xmlns => $nas->ns } );
+ push (@args, SOAP::Data->name("InterfaceHandle" => $if));
+ push (@args, SOAP::Data->name("InterfaceDescriptor" =>
+ \SOAP::Data->value(@ifdesc)));
+
+ dump_request($nas, $method, @args)
+ if $amt_debug;
+
+ my $ret = $nas->call($method, @args);
+ print_result($ret);
+}
+
#############################################################################
# main
@@ -223,7 +351,12 @@ soap_init;
if ($amt_command eq "info") {
print_general_info;
print_remote_info;
+} 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);
} elsif ($amt_command =~ m/^(reset|powerup|powerdown|powercycle)$/) {
remote_control($amt_command);
} else {