OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [dejagnu/] [lib/] [telnet.exp] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 97, 98, 1999 Free Software Foundation, Inc.
2
 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# DejaGnu@cygnus.com
19
 
20
#
21
# Connect using telnet. This takes two arguments. The first one is the
22
# hostname, and the second is the optional port number. This sets
23
# the fileid field in the config array, and returns -1 for error, or the
24
# spawn id.
25
#
26
proc telnet_open { hostname args } {
27
    global verbose
28
    global connectmode
29
    global spawn_id
30
    global timeout
31
    global board_info
32
 
33
    set raw 0;
34
 
35
    if { [llength $args] > 0 } {
36
        if { [lindex $args 0] == "raw" } {
37
            set raw 1;
38
        }
39
    }
40
 
41
    set port 23
42
    if [board_info $hostname exists name] {
43
        set connhost [board_info $hostname name]
44
    } else {
45
        set connhost $hostname
46
    }
47
 
48
    if [board_info $connhost exists hostname] {
49
        set hostname [board_info $connhost hostname];
50
    }
51
 
52
    if [file exists /usr/kerberos/bin/telnet] {
53
        set telnet /usr/kerberos/bin/telnet;
54
    } else {
55
        set telnet telnet;
56
    }
57
 
58
    # Instead of unsetting it, let's return it. One connection at a
59
    # time, please.
60
    if [board_info $connhost exists fileid] {
61
        return [board_info $connhost fileid];
62
    }
63
    # get the hostname and port number from the config array
64
    if [board_info $connhost exists netport] {
65
        set type $hostname
66
        set hosttmp [split [board_info $connhost netport] ":"]
67
        set hostname [lindex $hosttmp 0]
68
        if { [llength $hosttmp] > 1 } {
69
            set port [lindex $hosttmp 1]
70
        }
71
        unset hosttmp
72
    } else {
73
        set type target
74
    }
75
    if [board_info $connhost exists shell_prompt] {
76
        set shell_prompt [board_info $connhost shell_prompt]
77
    }
78
    if ![info exists shell_prompt] {    # if no prompt, then set it to something generic
79
        set shell_prompt ".*> "
80
    }
81
 
82
    set tries 0
83
    set result -1
84
    set need_respawn 1;
85
    verbose "Starting a telnet connection to $hostname:$port $shell_prompt" 2
86
    while { $result < 0 && $tries <= 3 } {
87
        if { $need_respawn } {
88
            set need_respawn 0;
89
            spawn $telnet $hostname $port;
90
        }
91
        expect {
92
            "Trying " {
93
                exp_continue;
94
            }
95
            -re "$shell_prompt.*$" {
96
                verbose "Got prompt\n"
97
                set result 0
98
            }
99
            -re "nt Name:|ogin:" {
100
                if [board_info $connhost exists telnet_username] {
101
                    exp_send "[board_info $connhost telnet_username]\n";
102
                    exp_continue;
103
                }
104
                if [board_info $connhost exists username] {
105
                    exp_send "[board_info $connhost username]\n";
106
                    exp_continue;
107
                }
108
                perror "telnet: need to login"
109
                break
110
            }
111
            "assword:" {
112
                if [board_info $connhost exists telnet_password] {
113
                    exp_send "[board_info $connhost telnet_password]\n";
114
                    exp_continue;
115
                }
116
                if [board_info $connhost exists password] {
117
                    exp_send "[board_info $connhost password]\n";
118
                    exp_continue;
119
                }
120
                perror "telnet: need a password"
121
                break
122
            }
123
            -re "advance.*y/n.*\\?" {
124
                exp_send "n\n";
125
                exp_continue;
126
            }
127
            -re {([Aa]dvanced|[Ss]imple) or ([Ss]imple|[Aa]dvanced)} {
128
                exp_send "simple\n";
129
                exp_continue;
130
            }
131
            "Connected to" {
132
                exp_continue
133
            }
134
            "unknown host" {
135
                exp_send "\003"
136
                perror "telnet: unknown host"
137
                break
138
            }
139
            "VxWorks Boot" {
140
                exp_send "@\n";
141
                sleep 20;
142
                exp_continue;
143
            }
144
            -re "Escape character is.*\\.\[\r\n\]" {
145
                if { $raw || [board_info $connhost exists dont_wait_for_prompt] } {
146
                    set result 0;
147
                } else {
148
                    if [board_info $connhost exists send_initial_cr] {
149
                        exp_send "\n"
150
                    }
151
                    exp_continue
152
                }
153
            }
154
            "has logged on from" {
155
                exp_continue
156
            }
157
            "You have no Kerberos tickets" {
158
                warning "telnet: no kerberos Tickets, please kinit"
159
                break
160
            }
161
            -re "Connection refused.*$" {
162
                catch "exp_send \"\003\"" foo;
163
                sleep 5;
164
                warning "telnet: connection refused."
165
            }
166
            -re "Sorry, this system is engaged.*" {
167
                exp_send "\003"
168
                warning "telnet: already connected."
169
            }
170
            "Connection closed by foreign host.*$" {
171
                warning "telnet: connection closed by foreign host."
172
                break
173
            }
174
            -re "\[\r\n\]+" {
175
                exp_continue
176
            }
177
            timeout {
178
                exp_send "\n"
179
            }
180
            eof {
181
                warning "telnet: got unexpected EOF from telnet."
182
                catch close;
183
                catch wait;
184
                set need_respawn 1;
185
                sleep 5;
186
            }
187
        }
188
        incr tries
189
    }
190
    # we look for this here again cause it means something went wrong, and
191
    # it doesn't always show up in the expect in buffer till the server times out.
192
    if [info exists expect_out(buffer)] {
193
        if [regexp "assword:|ogin:" $expect_out(buffer)] {
194
            perror "telnet: need to supply a login and password."
195
        }
196
    }
197
    if { $result < 0 } {
198
        catch close
199
        catch wait
200
        set spawn_id -1
201
    }
202
    if { $spawn_id >= 0 } {
203
        verbose "setting board_info($connhost,fileid) to $spawn_id" 3
204
        set board_info($connhost,fileid) $spawn_id
205
    }
206
    return $spawn_id
207
}
208
 
209
#
210
# Put the telnet connection into binary mode.
211
#
212
proc telnet_binary { hostname } {
213
    if [board_info $hostname exists fileid] {
214
        remote_send $hostname "";
215
        remote_expect $hostname 5 {
216
            -re "telnet> *$" {}
217
            default {}
218
        }
219
        remote_send $hostname "set binary\n"
220
        remote_expect $hostname 5 {
221
            -re "Format is .*telnet> *$" {
222
                remote_send $hostname "toggle binary\n";
223
                exp_continue;
224
            }
225
            -re "Negotiating network ascii.*telnet> *$" {
226
                remote_send $hostname "toggle binary\n";
227
                exp_continue;
228
            }
229
            -re "Negotiating binary.*\[\r\n\].*$" { }
230
            -re "binary.*unknown argument.*telnet> *$" {
231
                remote_send $hostname "mode character\n";
232
            }
233
            -re "Already operating in binary.*\[\r\n\].*$" { }
234
            timeout {
235
                warning "Never got binary response from telnet."
236
            }
237
        }
238
    }
239
}
240
 
241
proc telnet_transmit { dest file args } {
242
    return [standard_transmit $dest $file];
243
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.