1 |
package Intel::AMT::Redir; |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
use IO::Socket::INET; |
7 |
use Data::Dump qw/dump/; |
8 |
|
9 |
sub hdump { |
10 |
my $data = shift; |
11 |
my $out = unpack('H*', $data),$/; |
12 |
$out =~ s/(..)/$1 /g; |
13 |
warn $out,$/; |
14 |
} |
15 |
|
16 |
our $sock; |
17 |
|
18 |
sub connect { |
19 |
my ( $host ) = shift; |
20 |
my $port = 16994; |
21 |
|
22 |
my $user = 'admin'; |
23 |
my $passwd = $ENV{AMT_PASSWORD}; |
24 |
|
25 |
warn 'connect ', $host, ':', $port; |
26 |
|
27 |
$sock = IO::Socket::INET->new( |
28 |
PeerAddr => $host, |
29 |
PeerPort => $port, |
30 |
); |
31 |
|
32 |
$sock->autoflush(1); |
33 |
|
34 |
put( pack('C4A4', 0x10, 0, 0, 0, "SOL ") ); |
35 |
get( 0x11, 13 ); |
36 |
|
37 |
my $credentials = pack('CA*CA*', length($user), $user, length($passwd), $passwd); |
38 |
|
39 |
put( pack('C9', 0x13, 0, 0, 0, 0x01, length($credentials), 0, 0, 0) . $credentials ); |
40 |
get( 0x14, 9 ); |
41 |
|
42 |
} |
43 |
|
44 |
sub put { |
45 |
my ( $data ) = shift; |
46 |
hdump $data; |
47 |
syswrite $sock, $data, length($data); |
48 |
} |
49 |
|
50 |
sub get { |
51 |
my ( $expect, $len ) = @_; |
52 |
|
53 |
my $reply; |
54 |
sysread $sock,$reply,$len; |
55 |
hdump $reply; |
56 |
|
57 |
my ( $op, $error ) = unpack('CC', $reply); |
58 |
die "expected $expect got $op" unless $op == $expect; |
59 |
die "error" unless $error == 0x00; |
60 |
|
61 |
return $reply; |
62 |
} |
63 |
|
64 |
1; |
65 |
|