summaryrefslogtreecommitdiffstats
path: root/gatchat
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2011-07-26 15:59:47 +0200
committerMarcel Holtmann <marcel@holtmann.org>2011-07-26 15:59:47 +0200
commit0f29c33c5b823198e8288b5785a0aeaeb8b9b78c (patch)
treef70ef6d4d5699f34b6094fce766b39b45d0ff315 /gatchat
parenta58f01316bea8a4a9fad5663c862722ac753ec3a (diff)
downloadofono-0f29c33c5b823198e8288b5785a0aeaeb8b9b78c.tar.bz2
gatchat: Add helper for opening QCDM ports
Diffstat (limited to 'gatchat')
-rw-r--r--gatchat/gattty.c33
-rw-r--r--gatchat/gattty.h2
2 files changed, 35 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;
diff --git a/gatchat/gattty.h b/gatchat/gattty.h
index dc3fe160..e4d7c31f 100644
--- a/gatchat/gattty.h
+++ b/gatchat/gattty.h
@@ -43,6 +43,8 @@ extern "C" {
*/
GIOChannel *g_at_tty_open(const char *tty, GHashTable *options);
+GIOChannel *g_at_tty_open_qcdm(const char *tty);
+
#ifdef __cplusplus
}
#endif