From: Santtu Lakkala <inz@inz.fi>
To: ofono@ofono.org
Subject: [PATCH] Add support for tty on character device.
Date: Mon, 15 Jun 2009 20:13:25 +0300 [thread overview]
Message-ID: <4A368135.8070805@inz.fi> (raw)
[-- Attachment #1: Type: text/plain, Size: 2314 bytes --]
Adds support for using ttys through a serial device directly.
Signed-off-by: Santtu Lakkala <inz@inz.fi>
---
drivers/atmodem/session.c | 36 ++++++++++++++++++++++++++++--------
1 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/drivers/atmodem/session.c b/drivers/atmodem/session.c
index 2301756..3a9e49b 100644
--- a/drivers/atmodem/session.c
+++ b/drivers/atmodem/session.c
@@ -77,7 +77,7 @@ static gboolean connect_cb(GIOChannel *io,
GIOCondition cond, gpointer user)
socklen_t len = sizeof(err);
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len) < 0)
- err = errno;
+ err = errno == ENOTSOCK ? 0 : errno;
} else if (cond & (G_IO_HUP | G_IO_ERR))
err = ECONNRESET;
@@ -101,29 +101,47 @@ static gboolean connect_timeout(gpointer user)
return FALSE;
}
-#if 0
-static int tty_open(const char *tty, struct termios *ti)
+static GIOChannel *tty_connect(const char *tty)
{
+ GIOChannel *io;
int sk;
+ struct termios newtio;
sk = open(tty, O_RDWR | O_NOCTTY);
if (sk < 0) {
ofono_error("Can't open TTY %s: %s(%d)",
tty, strerror(errno), errno);
- return -1;
+ return NULL;
}
- if (ti && tcsetattr(sk, TCSANOW, ti) < 0) {
+ newtio.c_cflag = B115200 | CRTSCTS | CLOCAL | CREAD;
+ newtio.c_iflag = IGNPAR;
+ newtio.c_oflag = 0;
+ newtio.c_lflag = 0;
+
+ newtio.c_cc[VTIME] = 1;
+ newtio.c_cc[VMIN] = 5;
+
+ tcflush(sk, TCIFLUSH);
+ if (tcsetattr(sk, TCSANOW, &newtio) < 0) {
ofono_error("Can't change serial settings: %s(%d)",
strerror(errno), errno);
close(sk);
- return -1;
+ return NULL;
}
- return sk;
+ io = g_io_channel_unix_new(sk);
+ g_io_channel_set_close_on_unref(io, TRUE);
+
+ if (g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK,
+ NULL) != G_IO_STATUS_NORMAL) {
+ g_io_channel_unref(io);
+ return NULL;
+ }
+
+ return io;
}
-#endif
static GIOChannel *socket_common(int sk, struct sockaddr *addr,
socklen_t addrlen)
@@ -233,6 +251,8 @@ GIOChannel *modem_session_create(const char *target,
io = tcp_connect(target+4);
else if (!strncasecmp(target, "unix:", 5))
io = unix_connect(target+5);
+ else if (!strncasecmp(target, "dev:", 4))
+ io = tty_connect(target+4);
if (io == NULL)
return NULL;
--
debian.1.6.1.2.1
next reply other threads:[~2009-06-15 17:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-15 17:13 Santtu Lakkala [this message]
2009-07-01 19:51 ` [PATCH] Add support for tty on character device Aki Niemi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A368135.8070805@inz.fi \
--to=inz@inz.fi \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox