2006-08-28 11:13:56 +00:00
|
|
|
/*
|
|
|
|
* Serial back end (Windows-specific).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
|
|
|
#define SERIAL_MAX_BACKLOG 4096
|
|
|
|
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
typedef struct Serial Serial;
|
|
|
|
struct Serial {
|
2006-08-28 11:13:56 +00:00
|
|
|
HANDLE port;
|
|
|
|
struct handle *out, *in;
|
2018-09-12 08:10:51 +00:00
|
|
|
Frontend *frontend;
|
2006-08-28 11:13:56 +00:00
|
|
|
int bufsize;
|
2006-08-29 18:20:57 +00:00
|
|
|
long clearbreak_time;
|
|
|
|
int break_in_progress;
|
2018-09-11 15:23:38 +00:00
|
|
|
Backend backend;
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
};
|
2006-08-28 11:13:56 +00:00
|
|
|
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
static void serial_terminate(Serial *serial)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
if (serial->out) {
|
|
|
|
handle_free(serial->out);
|
|
|
|
serial->out = NULL;
|
|
|
|
}
|
|
|
|
if (serial->in) {
|
|
|
|
handle_free(serial->in);
|
|
|
|
serial->in = NULL;
|
|
|
|
}
|
2006-08-29 18:32:44 +00:00
|
|
|
if (serial->port != INVALID_HANDLE_VALUE) {
|
2006-08-29 18:20:57 +00:00
|
|
|
if (serial->break_in_progress)
|
|
|
|
ClearCommBreak(serial->port);
|
2006-08-28 11:13:56 +00:00
|
|
|
CloseHandle(serial->port);
|
2006-08-29 18:32:44 +00:00
|
|
|
serial->port = INVALID_HANDLE_VALUE;
|
2006-08-28 11:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serial_gotdata(struct handle *h, void *data, int len)
|
|
|
|
{
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
Serial *serial = (Serial *)handle_get_privdata(h);
|
2006-08-28 11:13:56 +00:00
|
|
|
if (len <= 0) {
|
|
|
|
const char *error_msg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Currently, len==0 should never happen because we're
|
|
|
|
* ignoring EOFs. However, it seems not totally impossible
|
|
|
|
* that this same back end might be usable to talk to named
|
|
|
|
* pipes or some other non-serial device, in which case EOF
|
|
|
|
* may become meaningful here.
|
|
|
|
*/
|
|
|
|
if (len == 0)
|
|
|
|
error_msg = "End of file reading from serial device";
|
|
|
|
else
|
|
|
|
error_msg = "Error reading from serial device";
|
|
|
|
|
|
|
|
serial_terminate(serial);
|
|
|
|
|
|
|
|
notify_remote_exit(serial->frontend);
|
|
|
|
|
|
|
|
logevent(serial->frontend, error_msg);
|
|
|
|
|
|
|
|
connection_fatal(serial->frontend, "%s", error_msg);
|
|
|
|
|
|
|
|
return 0; /* placate optimiser */
|
|
|
|
} else {
|
|
|
|
return from_backend(serial->frontend, 0, data, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void serial_sentdata(struct handle *h, int new_backlog)
|
|
|
|
{
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
Serial *serial = (Serial *)handle_get_privdata(h);
|
2006-08-28 11:13:56 +00:00
|
|
|
if (new_backlog < 0) {
|
|
|
|
const char *error_msg = "Error writing to serial device";
|
|
|
|
|
|
|
|
serial_terminate(serial);
|
|
|
|
|
|
|
|
notify_remote_exit(serial->frontend);
|
|
|
|
|
|
|
|
logevent(serial->frontend, error_msg);
|
|
|
|
|
|
|
|
connection_fatal(serial->frontend, "%s", error_msg);
|
|
|
|
} else {
|
|
|
|
serial->bufsize = new_backlog;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
static const char *serial_configure(Serial *serial, HANDLE serport, Conf *conf)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
DCB dcb;
|
|
|
|
COMMTIMEOUTS timeouts;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the serial port parameters. If we can't even
|
|
|
|
* GetCommState, we ignore the problem on the grounds that the
|
|
|
|
* user might have pointed us at some other type of two-way
|
|
|
|
* device instead of a serial port.
|
|
|
|
*/
|
|
|
|
if (GetCommState(serport, &dcb)) {
|
|
|
|
char *msg;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Boilerplate.
|
|
|
|
*/
|
|
|
|
dcb.fBinary = TRUE;
|
|
|
|
dcb.fDtrControl = DTR_CONTROL_ENABLE;
|
|
|
|
dcb.fDsrSensitivity = FALSE;
|
|
|
|
dcb.fTXContinueOnXoff = FALSE;
|
|
|
|
dcb.fOutX = FALSE;
|
|
|
|
dcb.fInX = FALSE;
|
|
|
|
dcb.fErrorChar = FALSE;
|
|
|
|
dcb.fNull = FALSE;
|
|
|
|
dcb.fRtsControl = RTS_CONTROL_ENABLE;
|
|
|
|
dcb.fAbortOnError = FALSE;
|
|
|
|
dcb.fOutxCtsFlow = FALSE;
|
|
|
|
dcb.fOutxDsrFlow = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configurable parameters.
|
|
|
|
*/
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
dcb.BaudRate = conf_get_int(conf, CONF_serspeed);
|
2016-04-10 13:25:34 +00:00
|
|
|
msg = dupprintf("Configuring baud rate %lu", dcb.BaudRate);
|
2006-08-28 11:13:56 +00:00
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
dcb.ByteSize = conf_get_int(conf, CONF_serdatabits);
|
2016-04-10 13:25:34 +00:00
|
|
|
msg = dupprintf("Configuring %u data bits", dcb.ByteSize);
|
2006-08-28 11:13:56 +00:00
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
switch (conf_get_int(conf, CONF_serstopbits)) {
|
2006-08-28 11:13:56 +00:00
|
|
|
case 2: dcb.StopBits = ONESTOPBIT; str = "1"; break;
|
|
|
|
case 3: dcb.StopBits = ONE5STOPBITS; str = "1.5"; break;
|
|
|
|
case 4: dcb.StopBits = TWOSTOPBITS; str = "2"; break;
|
|
|
|
default: return "Invalid number of stop bits (need 1, 1.5 or 2)";
|
|
|
|
}
|
|
|
|
msg = dupprintf("Configuring %s data bits", str);
|
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
switch (conf_get_int(conf, CONF_serparity)) {
|
2006-08-28 11:13:56 +00:00
|
|
|
case SER_PAR_NONE: dcb.Parity = NOPARITY; str = "no"; break;
|
|
|
|
case SER_PAR_ODD: dcb.Parity = ODDPARITY; str = "odd"; break;
|
|
|
|
case SER_PAR_EVEN: dcb.Parity = EVENPARITY; str = "even"; break;
|
|
|
|
case SER_PAR_MARK: dcb.Parity = MARKPARITY; str = "mark"; break;
|
|
|
|
case SER_PAR_SPACE: dcb.Parity = SPACEPARITY; str = "space"; break;
|
|
|
|
}
|
|
|
|
msg = dupprintf("Configuring %s parity", str);
|
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
switch (conf_get_int(conf, CONF_serflow)) {
|
2006-08-28 11:13:56 +00:00
|
|
|
case SER_FLOW_NONE:
|
|
|
|
str = "no";
|
|
|
|
break;
|
|
|
|
case SER_FLOW_XONXOFF:
|
|
|
|
dcb.fOutX = dcb.fInX = TRUE;
|
|
|
|
str = "XON/XOFF";
|
|
|
|
break;
|
|
|
|
case SER_FLOW_RTSCTS:
|
|
|
|
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
|
|
|
|
dcb.fOutxCtsFlow = TRUE;
|
|
|
|
str = "RTS/CTS";
|
|
|
|
break;
|
|
|
|
case SER_FLOW_DSRDTR:
|
|
|
|
dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
|
|
|
|
dcb.fOutxDsrFlow = TRUE;
|
|
|
|
str = "DSR/DTR";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
msg = dupprintf("Configuring %s flow control", str);
|
|
|
|
logevent(serial->frontend, msg);
|
|
|
|
sfree(msg);
|
|
|
|
|
|
|
|
if (!SetCommState(serport, &dcb))
|
|
|
|
return "Unable to configure serial port";
|
|
|
|
|
|
|
|
timeouts.ReadIntervalTimeout = 1;
|
|
|
|
timeouts.ReadTotalTimeoutMultiplier = 0;
|
|
|
|
timeouts.ReadTotalTimeoutConstant = 0;
|
|
|
|
timeouts.WriteTotalTimeoutMultiplier = 0;
|
|
|
|
timeouts.WriteTotalTimeoutConstant = 0;
|
|
|
|
if (!SetCommTimeouts(serport, &timeouts))
|
|
|
|
return "Unable to configure serial timeouts";
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set up the serial connection.
|
|
|
|
*
|
|
|
|
* Returns an error message, or NULL on success.
|
|
|
|
*
|
|
|
|
* Also places the canonical host name into `realhost'. It must be
|
|
|
|
* freed by the caller.
|
|
|
|
*/
|
2018-09-12 08:10:51 +00:00
|
|
|
static const char *serial_init(Frontend *frontend, Backend **backend_handle,
|
2015-05-15 10:15:42 +00:00
|
|
|
Conf *conf, const char *host, int port,
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
char **realhost, int nodelay, int keepalive)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
Serial *serial;
|
2006-08-28 11:13:56 +00:00
|
|
|
HANDLE serport;
|
|
|
|
const char *err;
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
char *serline;
|
2006-08-28 11:13:56 +00:00
|
|
|
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
serial = snew(Serial);
|
2006-08-29 18:32:44 +00:00
|
|
|
serial->port = INVALID_HANDLE_VALUE;
|
2006-08-28 11:13:56 +00:00
|
|
|
serial->out = serial->in = NULL;
|
2006-08-28 11:32:12 +00:00
|
|
|
serial->bufsize = 0;
|
2006-08-29 18:20:57 +00:00
|
|
|
serial->break_in_progress = FALSE;
|
2018-09-11 15:23:38 +00:00
|
|
|
serial->backend.vt = &serial_backend;
|
|
|
|
*backend_handle = &serial->backend;
|
2006-08-28 11:13:56 +00:00
|
|
|
|
2018-09-12 08:10:51 +00:00
|
|
|
serial->frontend = frontend;
|
2006-08-28 11:13:56 +00:00
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
serline = conf_get_str(conf, CONF_serline);
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
char *msg = dupprintf("Opening serial device %s", serline);
|
2006-08-28 11:13:56 +00:00
|
|
|
logevent(serial->frontend, msg);
|
2017-02-14 20:42:26 +00:00
|
|
|
sfree(msg);
|
2006-08-28 11:13:56 +00:00
|
|
|
}
|
|
|
|
|
2007-02-28 21:30:06 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Munge the string supplied by the user into a Windows filename.
|
|
|
|
*
|
|
|
|
* Windows supports opening a few "legacy" devices (including
|
|
|
|
* COM1-9) by specifying their names verbatim as a filename to
|
|
|
|
* open. (Thus, no files can ever have these names. See
|
|
|
|
* <http://msdn2.microsoft.com/en-us/library/aa365247.aspx>
|
|
|
|
* ("Naming a File") for the complete list of reserved names.)
|
|
|
|
*
|
|
|
|
* However, this doesn't let you get at devices COM10 and above.
|
|
|
|
* For that, you need to specify a filename like "\\.\COM10".
|
|
|
|
* This is also necessary for special serial and serial-like
|
|
|
|
* devices such as \\.\WCEUSBSH001. It also works for the "legacy"
|
|
|
|
* names, so you can do \\.\COM1 (verified as far back as Win95).
|
|
|
|
* See <http://msdn2.microsoft.com/en-us/library/aa363858.aspx>
|
|
|
|
* (CreateFile() docs).
|
|
|
|
*
|
|
|
|
* So, we believe that prepending "\\.\" should always be the
|
|
|
|
* Right Thing. However, just in case someone finds something to
|
|
|
|
* talk to that doesn't exist under there, if the serial line
|
|
|
|
* contains a backslash, we use it verbatim. (This also lets
|
|
|
|
* existing configurations using \\.\ continue working.)
|
|
|
|
*/
|
|
|
|
char *serfilename =
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
dupprintf("%s%s", strchr(serline, '\\') ? "" : "\\\\.\\", serline);
|
2007-02-28 21:30:06 +00:00
|
|
|
serport = CreateFile(serfilename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
|
|
|
sfree(serfilename);
|
|
|
|
}
|
|
|
|
|
2006-08-28 11:13:56 +00:00
|
|
|
if (serport == INVALID_HANDLE_VALUE)
|
|
|
|
return "Unable to open serial port";
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
err = serial_configure(serial, serport, conf);
|
2006-08-28 11:13:56 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
serial->port = serport;
|
|
|
|
serial->out = handle_output_new(serport, serial_sentdata, serial,
|
|
|
|
HANDLE_FLAG_OVERLAPPED);
|
|
|
|
serial->in = handle_input_new(serport, serial_gotdata, serial,
|
|
|
|
HANDLE_FLAG_OVERLAPPED |
|
2006-08-28 18:26:50 +00:00
|
|
|
HANDLE_FLAG_IGNOREEOF |
|
|
|
|
HANDLE_FLAG_UNITBUFFER);
|
2006-08-28 11:13:56 +00:00
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
*realhost = dupstr(serline);
|
2006-08-28 11:13:56 +00:00
|
|
|
|
2006-08-29 18:20:57 +00:00
|
|
|
/*
|
|
|
|
* Specials are always available.
|
|
|
|
*/
|
|
|
|
update_specials_menu(serial->frontend);
|
|
|
|
|
2006-08-28 11:13:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_free(Backend *be)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
Serial *serial = container_of(be, Serial, backend);
|
2006-08-28 11:13:56 +00:00
|
|
|
|
|
|
|
serial_terminate(serial);
|
2006-08-29 18:20:57 +00:00
|
|
|
expire_timer_context(serial);
|
2006-08-28 11:13:56 +00:00
|
|
|
sfree(serial);
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_reconfig(Backend *be, Conf *conf)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
Serial *serial = container_of(be, Serial, backend);
|
2006-08-28 11:13:56 +00:00
|
|
|
|
2018-06-03 20:48:08 +00:00
|
|
|
serial_configure(serial, serial->port, conf);
|
2006-08-28 11:13:56 +00:00
|
|
|
|
|
|
|
/*
|
2018-06-03 20:48:08 +00:00
|
|
|
* FIXME: what should we do if that call returned a non-NULL error
|
|
|
|
* message?
|
2006-08-28 11:13:56 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to send data down the serial connection.
|
|
|
|
*/
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_send(Backend *be, const char *buf, int len)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
Serial *serial = container_of(be, Serial, backend);
|
2006-08-28 11:13:56 +00:00
|
|
|
|
|
|
|
if (serial->out == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
serial->bufsize = handle_write(serial->out, buf, len);
|
|
|
|
return serial->bufsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to query the current sendability status.
|
|
|
|
*/
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_sendbuffer(Backend *be)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
Serial *serial = container_of(be, Serial, backend);
|
2006-08-28 11:13:56 +00:00
|
|
|
return serial->bufsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set the size of the window
|
|
|
|
*/
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_size(Backend *be, int width, int height)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-18 21:42:48 +00:00
|
|
|
static void serbreak_timer(void *ctx, unsigned long now)
|
2006-08-29 18:20:57 +00:00
|
|
|
{
|
Get rid of lots of implicit pointer types.
All the main backend structures - Ssh, Telnet, Pty, Serial etc - now
describe structure types themselves rather than pointers to them. The
same goes for the codebase-wide trait types Socket and Plug, and the
supporting types SockAddr and Pinger.
All those things that were typedefed as pointers are older types; the
newer ones have the explicit * at the point of use, because that's
what I now seem to be preferring. But whichever one of those is
better, inconsistently using a mixture of the two styles is worse, so
let's make everything consistent.
A few types are still implicitly pointers, such as Bignum and some of
the GSSAPI types; generally this is either because they have to be
void *, or because they're typedefed differently on different
platforms and aren't always pointers at all. Can't be helped. But I've
got rid of the main ones, at least.
2018-10-04 18:10:23 +00:00
|
|
|
Serial *serial = (Serial *)ctx;
|
2006-08-29 18:20:57 +00:00
|
|
|
|
2012-09-18 21:42:48 +00:00
|
|
|
if (now == serial->clearbreak_time && serial->port) {
|
2006-08-29 18:20:57 +00:00
|
|
|
ClearCommBreak(serial->port);
|
|
|
|
serial->break_in_progress = FALSE;
|
|
|
|
logevent(serial->frontend, "Finished serial break");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-28 11:13:56 +00:00
|
|
|
/*
|
|
|
|
* Send serial special codes.
|
|
|
|
*/
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static void serial_special(Backend *be, SessionSpecialCode code, int arg)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
Serial *serial = container_of(be, Serial, backend);
|
2006-08-29 18:20:57 +00:00
|
|
|
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
if (serial->port && code == SS_BRK) {
|
2006-08-29 18:20:57 +00:00
|
|
|
logevent(serial->frontend, "Starting serial break at user request");
|
|
|
|
SetCommBreak(serial->port);
|
|
|
|
/*
|
|
|
|
* To send a serial break on Windows, we call SetCommBreak
|
|
|
|
* to begin the break, then wait a bit, and then call
|
|
|
|
* ClearCommBreak to finish it. Hence, I must use timing.c
|
|
|
|
* to arrange a callback when it's time to do the latter.
|
|
|
|
*
|
|
|
|
* SUS says that a default break length must be between 1/4
|
|
|
|
* and 1/2 second. FreeBSD apparently goes with 2/5 second,
|
|
|
|
* and so will I.
|
|
|
|
*/
|
|
|
|
serial->clearbreak_time =
|
|
|
|
schedule_timer(TICKSPERSEC * 2 / 5, serbreak_timer, serial);
|
|
|
|
serial->break_in_progress = TRUE;
|
|
|
|
}
|
|
|
|
|
2006-08-28 11:13:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a list of the special codes that make sense in this
|
|
|
|
* protocol.
|
|
|
|
*/
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static const SessionSpecial *serial_get_specials(Backend *be)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static const SessionSpecial specials[] = {
|
|
|
|
{"Break", SS_BRK},
|
|
|
|
{NULL, SS_EXITMENU}
|
2006-08-29 18:20:57 +00:00
|
|
|
};
|
|
|
|
return specials;
|
2006-08-28 11:13:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_connected(Backend *be)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
return 1; /* always connected */
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_sendok(Backend *be)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_unthrottle(Backend *be, int backlog)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
Serial *serial = container_of(be, Serial, backend);
|
2006-08-28 11:13:56 +00:00
|
|
|
if (serial->in)
|
|
|
|
handle_unthrottle(serial->in, backlog);
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_ldisc(Backend *be, int option)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Local editing and local echo are off by default.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_provide_ldisc(Backend *be, Ldisc *ldisc)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
/* This is a stub. */
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void serial_provide_logctx(Backend *be, LogContext *logctx)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
/* This is a stub. */
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_exitcode(Backend *be)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
Serial *serial = container_of(be, Serial, backend);
|
2006-08-29 18:32:44 +00:00
|
|
|
if (serial->port != INVALID_HANDLE_VALUE)
|
2006-08-28 11:13:56 +00:00
|
|
|
return -1; /* still connected */
|
|
|
|
else
|
|
|
|
/* Exit codes are a meaningless concept with serial ports */
|
|
|
|
return INT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cfg_info for Serial does nothing at all.
|
|
|
|
*/
|
2018-09-11 15:23:38 +00:00
|
|
|
static int serial_cfg_info(Backend *be)
|
2006-08-28 11:13:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-05 06:03:46 +00:00
|
|
|
const struct BackendVtable serial_backend = {
|
2006-08-28 11:13:56 +00:00
|
|
|
serial_init,
|
|
|
|
serial_free,
|
|
|
|
serial_reconfig,
|
|
|
|
serial_send,
|
|
|
|
serial_sendbuffer,
|
|
|
|
serial_size,
|
|
|
|
serial_special,
|
|
|
|
serial_get_specials,
|
|
|
|
serial_connected,
|
|
|
|
serial_exitcode,
|
|
|
|
serial_sendok,
|
|
|
|
serial_ldisc,
|
|
|
|
serial_provide_ldisc,
|
|
|
|
serial_provide_logctx,
|
|
|
|
serial_unthrottle,
|
|
|
|
serial_cfg_info,
|
2015-09-25 10:46:28 +00:00
|
|
|
NULL /* test_for_upstream */,
|
2007-06-30 21:56:44 +00:00
|
|
|
"serial",
|
|
|
|
PROT_SERIAL,
|
2007-07-01 15:47:31 +00:00
|
|
|
0
|
2006-08-28 11:13:56 +00:00
|
|
|
};
|