+ } else {
+ $conn = AGWMsg->new($rproc);
+ $conn->{agwpid} = $pid;
+ $conn->{agwport} = $port;
+ $conn->{lineend} = "\cM";
+ $conn->{incoming} = 1;
+ $conn->{agwcall} = $call;
+ $circuit{$call} = $conn;
+ if (my ($c, $s) = $call =~ /^(\w+)-(\d\d?)$/) {
+ $s = 15 - $s if $s > 8;
+ $call = $s > 0 ? "${c}-${s}" : $c;
+ }
+ $conn->to_connected($call, 'A', $conn->{csort} = 'ax25');
+ }
+ } elsif ($sort eq 'd') {
+ my $d = unpack "Z*", $data;
+ $d =~ s/\cM\cJ?$//;
+ dbg("AGW '$from'->'$to' port: $port Disconnected ($d)") if isdbg('agw');
+ my $conn = _find($from eq $main::mycall ? $to : $from);
+ if ($conn) {
+ &{$conn->{eproc}}() if $conn->{eproc};
+ $conn->in_disconnect;
+ }
+ } elsif ($sort eq 'y') {
+ my ($frames) = unpack "V", $data;
+ dbg("AGW Frames Outstanding on port $port = $frames") if isdbg('agwpollans');
+ my $conn = _find($from);
+ $conn->{oframes} = $frames if $conn;
+ } elsif ($sort eq 'Y') {
+ my ($frames) = unpack "V", $data;
+ dbg("AGW Frames Outstanding on circuit '$from'->'$to' = $frames") if isdbg('agw');
+ my $conn = _find($from eq $main::mycall ? $to : $from);
+ $conn->{oframes} = $frames if $conn;
+ } elsif ($sort eq 'H') {
+ unless ($from =~ /^\s+$/) {
+ my $d = unpack "Z*", $data;
+ $d =~ s/\cM\cJ?$//;
+ dbg("AGW Heard port: $port \"$d\"") if isdbg('agw');
+ }
+ } elsif ($sort eq 'X') {
+ my ($r) = unpack "C", $data;
+ $r = $r ? "Successful" : "Failed";
+ dbg("AGW Register $from $r");
+ finish() unless $r;
+ } elsif ($sort eq 'R') {
+ my ($major, $minor) = unpack "v x2 v x2", $data;
+ dbg("AGW Version $major.$minor") if isdbg('agw');
+ } elsif ($sort eq 'G') {
+ my @ports = split /;/, $data;
+ $noports = shift @ports || '0';
+ dbg("AGW $noports Ports available") if isdbg('agw');
+ pop @ports while @ports > $noports;
+ for (@ports) {
+ next unless $_;
+ dbg("AGW Port: $_") if isdbg('agw');
+ }
+ for (my $i = 0; $i < $noports; $i++) {
+ _sendf('y', undef, undef, $i);
+ _sendf('g', undef, undef, $i);