All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add support for tty on character device.
@ 2009-06-15 17:13 Santtu Lakkala
  2009-07-01 19:51 ` Aki Niemi
  0 siblings, 1 reply; 2+ messages in thread
From: Santtu Lakkala @ 2009-06-15 17:13 UTC (permalink / raw)
  To: ofono

[-- 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add support for tty on character device.
  2009-06-15 17:13 [PATCH] Add support for tty on character device Santtu Lakkala
@ 2009-07-01 19:51 ` Aki Niemi
  0 siblings, 0 replies; 2+ messages in thread
From: Aki Niemi @ 2009-07-01 19:51 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 174 bytes --]


On Mon, 15 Jun 2009 20:13:25 +0300, Santtu Lakkala <inz@inz.fi> wrote:
> Adds support for using ttys through a serial device directly.

Pushed, thanks!

Cheers,
Aki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-07-01 19:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-15 17:13 [PATCH] Add support for tty on character device Santtu Lakkala
2009-07-01 19:51 ` Aki Niemi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.