Refactor termios parsing for rfc2217 and debug
And show the termios on TCGETS too.
This commit is contained in:
@@ -712,6 +712,71 @@ static const char *_ioctl_name(int cmd)
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int _tio_parity(const struct termios *tio)
|
||||
{
|
||||
unsigned int par;
|
||||
|
||||
if (tio->c_cflag & PARENB && tio->c_iflag & IGNPAR)
|
||||
par = 1;
|
||||
#ifdef CMSPAR
|
||||
else if (tio->c_cflag & PARENB && tio->c_iflag & CMSPAR)
|
||||
{
|
||||
if (tio->c_cflag & PARODD)
|
||||
par = 4;
|
||||
else
|
||||
par = 5;
|
||||
}
|
||||
#endif
|
||||
else if (tio->c_cflag & PARENB)
|
||||
par = 3;
|
||||
else
|
||||
par = 1;
|
||||
|
||||
return par;
|
||||
}
|
||||
|
||||
static unsigned int _tio_baud(const struct termios *tio)
|
||||
{
|
||||
return baudrate(tio->c_cflag & (CBAUD | CBAUDEX));
|
||||
}
|
||||
|
||||
static unsigned int _tio_csize(const struct termios *tio)
|
||||
{
|
||||
unsigned int csize;
|
||||
|
||||
if ((tio->c_cflag & CSIZE) == CS5)
|
||||
csize = 5;
|
||||
else if ((tio->c_cflag & CSIZE) == CS6)
|
||||
csize = 6;
|
||||
else if ((tio->c_cflag & CSIZE) == CS7)
|
||||
csize = 7;
|
||||
else
|
||||
csize = 8;
|
||||
|
||||
return csize;
|
||||
}
|
||||
|
||||
static unsigned int _tio_stopb(const struct termios *tio)
|
||||
{
|
||||
unsigned int stopb;
|
||||
|
||||
if (tio->c_cflag & CSTOPB)
|
||||
stopb = 2;
|
||||
else
|
||||
stopb = 1;
|
||||
|
||||
return stopb;
|
||||
}
|
||||
|
||||
static void _show_termios(const char *txt, const struct termios *tio)
|
||||
{
|
||||
DBG("%s: %u%c%u%u %cCTSRTS %cCREAD %cHUPCL %cCLOCAL\n", txt,
|
||||
_tio_baud(tio), pstr[_tio_parity(tio)], _tio_csize(tio),
|
||||
_tio_stopb(tio),
|
||||
tio->c_cflag & CRTSCTS ? '+' : '-', tio->c_cflag & CREAD ? '+' : '-',
|
||||
tio->c_cflag & HUPCL ? '+' : '-', tio->c_cflag & CLOCAL ? '+' : '-');
|
||||
}
|
||||
|
||||
#define CHECK_BUF_IN(sz) \
|
||||
if (in_bufsz < sz) do { in_bufsz = sz; goto retry_in; } while(0)
|
||||
#define CHECK_BUF_OUT(sz) \
|
||||
@@ -743,47 +808,19 @@ ttynvt_ioctl(fuse_req_t req, int cmd, void *arg,
|
||||
case TCSETS:
|
||||
CHECK_BUF_IN(sizeof(struct termios));
|
||||
{
|
||||
speed_t speed;
|
||||
unsigned char csize, par, sb;
|
||||
|
||||
memcpy(tio, in_buf, in_bufsz);
|
||||
|
||||
speed = tio->c_cflag & (CBAUD | CBAUDEX);
|
||||
byte4 = htonl(baudrate(speed));
|
||||
byte4 = htonl(_tio_baud(tio));
|
||||
telnet_rfc2217_cfg(tty->tn, TNS_SET_BAUDRATE, &byte4, 4);
|
||||
|
||||
if ((tio->c_cflag & CSIZE) == CS5)
|
||||
csize = 5;
|
||||
else if ((tio->c_cflag & CSIZE) == CS6)
|
||||
csize = 6;
|
||||
else if ((tio->c_cflag & CSIZE) == CS7)
|
||||
csize = 7;
|
||||
else
|
||||
csize = 8;
|
||||
telnet_rfc2217_cfg(tty->tn, TNS_SET_DATASIZE, &csize, 1);
|
||||
byte = _tio_csize(tio);
|
||||
telnet_rfc2217_cfg(tty->tn, TNS_SET_DATASIZE, &byte, 1);
|
||||
|
||||
if (tio->c_cflag & PARENB && tio->c_iflag & IGNPAR)
|
||||
par = 1;
|
||||
#ifdef CMSPAR
|
||||
else if (tio->c_cflag & PARENB && tio->c_iflag & CMSPAR)
|
||||
{
|
||||
if (tio->c_cflag & PARODD)
|
||||
par = 4;
|
||||
else
|
||||
par = 5;
|
||||
}
|
||||
#endif
|
||||
else if (tio->c_cflag & PARENB)
|
||||
par = 3;
|
||||
else
|
||||
par = 1;
|
||||
telnet_rfc2217_cfg(tty->tn, TNS_SET_PARITY, &par, 1);
|
||||
byte = _tio_parity(tio);
|
||||
telnet_rfc2217_cfg(tty->tn, TNS_SET_PARITY, &byte, 1);
|
||||
|
||||
if (tio->c_cflag & CSTOPB)
|
||||
sb = 2;
|
||||
else
|
||||
sb = 1;
|
||||
telnet_rfc2217_cfg(tty->tn, TNS_SET_STOPSIZE, &sb, 1);
|
||||
byte = _tio_stopb(tio);
|
||||
telnet_rfc2217_cfg(tty->tn, TNS_SET_STOPSIZE, &byte, 1);
|
||||
|
||||
if (tio->c_cflag & CRTSCTS)
|
||||
{
|
||||
@@ -791,19 +828,13 @@ ttynvt_ioctl(fuse_req_t req, int cmd, void *arg,
|
||||
telnet_rfc2217_ctl(tty->tn, TNS_CTL_CTSRTS);
|
||||
}
|
||||
|
||||
if (!(tty->cmcr & TIOCM_DTR) && speed != B0)
|
||||
if (!(tty->cmcr & TIOCM_DTR) && _tio_baud(tio) != 0)
|
||||
{
|
||||
tty->cmcr |= TIOCM_DTR;
|
||||
telnet_rfc2217_ctl(tty->tn, TNS_CTL_DTR_ON);
|
||||
}
|
||||
|
||||
DBG("termios: %u%c%u%u %cCTSRTS %cCREAD %cHUPCL %cCLOCAL\n",
|
||||
baudrate(speed), pstr[par], csize, sb,
|
||||
tio->c_cflag & CRTSCTS ? '+' : '-',
|
||||
tio->c_cflag & CREAD ? '+' : '-',
|
||||
tio->c_cflag & HUPCL ? '+' : '-',
|
||||
tio->c_cflag & CLOCAL ? '+' : '-');
|
||||
|
||||
_show_termios("TCSETS", tio);
|
||||
ioctl(tty->fds[FD_SLAVE].fd, cmd, tio);
|
||||
|
||||
if (cmd == TCSETSF)
|
||||
@@ -815,6 +846,7 @@ ttynvt_ioctl(fuse_req_t req, int cmd, void *arg,
|
||||
case TCGETS:
|
||||
CHECK_BUF_OUT(sizeof(struct termios));
|
||||
ioctl(tty->fds[FD_SLAVE].fd, TCGETS, tio);
|
||||
_show_termios("TCGETS", tio);
|
||||
fuse_reply_ioctl(req, 0, tio, sizeof(struct termios));
|
||||
break;
|
||||
case TIOCINQ: /* Get the number of bytes in the input
|
||||
|
||||
Reference in New Issue
Block a user