diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2011-07-26 15:59:47 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2011-07-26 15:59:47 +0200 |
commit | 0f29c33c5b823198e8288b5785a0aeaeb8b9b78c (patch) | |
tree | f70ef6d4d5699f34b6094fce766b39b45d0ff315 /gatchat/gattty.c | |
parent | a58f01316bea8a4a9fad5663c862722ac753ec3a (diff) | |
download | ofono-0f29c33c5b823198e8288b5785a0aeaeb8b9b78c.tar.bz2 |
gatchat: Add helper for opening QCDM ports
Diffstat (limited to 'gatchat/gattty.c')
-rw-r--r-- | gatchat/gattty.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/gatchat/gattty.c b/gatchat/gattty.c index 02ca389d..5ac733c3 100644 --- a/gatchat/gattty.c +++ b/gatchat/gattty.c @@ -250,7 +250,40 @@ GIOChannel *g_at_tty_open(const char *tty, GHashTable *options) return NULL; channel = g_io_channel_unix_new(fd); + if (channel == NULL) { + close(fd); + return NULL; + } + g_io_channel_set_close_on_unref(channel, TRUE); + + return channel; +} + +GIOChannel *g_at_tty_open_qcdm(const char *tty) +{ + GIOChannel *channel; + struct termios ti; + int fd; + + fd = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fd < 0) + return NULL; + + /* Switch TTY to raw mode */ + memset(&ti, 0, sizeof(ti)); + cfmakeraw(&ti); + + /* No parity, 1 stop bit */ + ti.c_cflag &= ~(CSIZE | CSTOPB | PARENB); + ti.c_cflag |= (B115200 | CS8); + + if (tcsetattr (fd, TCSANOW, &ti) < 0) { + close(fd); + return NULL; + } + + channel = g_io_channel_unix_new(fd); if (channel == NULL) { close(fd); return NULL; |