diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-09-02 19:18:41 -0700 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-09-02 19:18:41 -0700 |
commit | f81fcb66ea05c5b59164135bd2b82cc32b3f6999 (patch) | |
tree | de73dadf5aa95c5d7ac7f91a4d8096095d2d65b1 | |
parent | aceaac4b7b06cc64bd872c095c5aa09a2a8b329d (diff) |
Remove the async TTY open helper and just use a blocking one
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | plugins/chat.c | 165 | ||||
-rw-r--r-- | plugins/chat.h | 29 | ||||
-rw-r--r-- | plugins/mbm.c | 49 |
4 files changed, 29 insertions, 216 deletions
diff --git a/Makefile.am b/Makefile.am index b3acd72f..af437dff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -92,8 +92,6 @@ if DATAFILES conf_DATA += plugins/modem.conf endif -builtin_sources += plugins/chat.h plugins/chat.c - builtin_modules += generic_at builtin_sources += plugins/generic_at.c diff --git a/plugins/chat.c b/plugins/chat.c deleted file mode 100644 index 251ba5c8..00000000 --- a/plugins/chat.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * - * oFono - Open Source Telephony - * - * Copyright (C) 2008-2009 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> -#include <string.h> -#include <termios.h> - -#include <glib.h> -#include <gatchat.h> -#include <gatsyntax.h> - -#include <ofono/log.h> - -#include "chat.h" - -struct chat_data { - GIOChannel *io; - guint timeout; - - chat_callback_t callback; - gpointer user_data; -}; - -static gboolean connect_callback(GIOChannel *io, - GIOCondition cond, gpointer user_data) -{ - struct chat_data *data = user_data; - GAtChat *chat; - GAtSyntax *syntax; - - if (cond & G_IO_NVAL) - return FALSE; - - if (cond & (G_IO_HUP | G_IO_ERR)) - return FALSE; - - syntax = g_at_syntax_new_gsmv1(); - chat = g_at_chat_new(io, syntax); - g_at_syntax_unref(syntax); - - if (!chat) - return FALSE; - - data->callback(chat, data->user_data); - - g_at_chat_unref(chat); - - return FALSE; -} - -static gboolean connect_timeout(gpointer user_data) -{ - struct chat_data *data = user_data; - - data->timeout = 0; - - g_io_channel_close(data->io); - - data->callback(NULL, data->user_data); - - return FALSE; -} - -static void connect_destroy(gpointer user_data) -{ - struct chat_data *data = user_data; - - if (data->timeout > 0) { - g_source_remove(data->timeout); - data->timeout = 0; - } - - data->io = NULL; -} - -int chat_connect(const char *device, chat_callback_t callback, - gpointer user_data) -{ - struct chat_data *data; - struct termios newtio; - int fd; - - data = g_try_new0(struct chat_data, 1); - if (!data) - return -ENOMEM; - - fd = open(device, O_RDWR | O_NOCTTY); - if (fd < 0) { - ofono_error("Can't open TTY %s: %s (%d)", - device, strerror(errno), errno); - g_free(data); - return -EIO; - } - - 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(fd, TCIFLUSH); - - if (tcsetattr(fd, TCSANOW, &newtio) < 0) { - ofono_error("Can't change TTY termios: %s (%d)", - strerror(errno), errno); - close(fd); - g_free(data); - return -EIO; - } - - data->io = g_io_channel_unix_new(fd); - - g_io_channel_set_close_on_unref(data->io, TRUE); - - if (g_io_channel_set_flags(data->io, G_IO_FLAG_NONBLOCK, - NULL) != G_IO_STATUS_NORMAL) { - g_io_channel_unref(data->io); - g_free(data); - return -EIO; - } - - data->callback = callback; - data->user_data = user_data; - - data->timeout = g_timeout_add_seconds(10, connect_timeout, data); - - g_io_add_watch_full(data->io, G_PRIORITY_DEFAULT, - G_IO_OUT | G_IO_ERR | G_IO_HUP | G_IO_NVAL, - connect_callback, data, connect_destroy); - - g_io_channel_unref(data->io); - - return 0; -} - -void chat_disconnect(GAtChat *chat) -{ -} diff --git a/plugins/chat.h b/plugins/chat.h deleted file mode 100644 index a9c2902b..00000000 --- a/plugins/chat.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * - * oFono - Open Source Telephony - * - * Copyright (C) 2008-2009 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include <glib.h> -#include <gatchat.h> - -typedef void (*chat_callback_t)(GAtChat *chat, gpointer user_data); - -int chat_connect(const char *device, chat_callback_t callback, - gpointer user_data); -void chat_disconnect(GAtChat *chat); diff --git a/plugins/mbm.c b/plugins/mbm.c index 09176a69..5fbb3a42 100644 --- a/plugins/mbm.c +++ b/plugins/mbm.c @@ -38,8 +38,6 @@ #include <ofono/sms.h> #include <ofono/log.h> -#include "chat.h" - struct mbm_data { GAtChat *chat; }; @@ -75,37 +73,47 @@ static void mbm_debug(const char *str, void *user_data) ofono_info("%s", str); } -static void connect_callback(GAtChat *chat, gpointer user_data) +static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) { struct ofono_modem *modem = user_data; + + DBG(""); + + if (ok) + ofono_modem_set_powered(modem, TRUE); +} + +static int mbm_enable(struct ofono_modem *modem) +{ struct mbm_data *data = ofono_modem_get_data(modem); + GAtSyntax *syntax; - if (!chat) { - ofono_modem_set_powered(modem, FALSE); - return; - } + DBG("%p", modem); - data->chat = g_at_chat_ref(chat); + syntax = g_at_syntax_new_gsmv1(); + data->chat = g_at_chat_new_from_tty("/dev/ttyACM0", syntax); + g_at_syntax_unref(syntax); + + if (!data->chat) + return -EIO; if (getenv("OFONO_AT_DEBUG")) g_at_chat_set_debug(data->chat, mbm_debug, NULL); - ofono_modem_set_powered(modem, TRUE); + g_at_chat_send(data->chat, "AT+CFUN=1", NULL, + cfun_enable, modem, NULL); - g_at_chat_send(data->chat, "AT+CFUN=1", NULL, NULL, NULL, NULL); + return 0; } -static int mbm_enable(struct ofono_modem *modem) +static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data) { - int err; - - DBG("%p", modem); + struct ofono_modem *modem = user_data; - err = chat_connect("/dev/ttyACM0", connect_callback, modem); - if (err < 0) - return err; + DBG(""); - return -EINPROGRESS; + if (ok) + ofono_modem_set_powered(modem, FALSE); } static int mbm_disable(struct ofono_modem *modem) @@ -117,9 +125,10 @@ static int mbm_disable(struct ofono_modem *modem) if (!data->chat) return 0; - g_at_chat_shutdown(data->chat); + g_at_chat_send(data->chat, "AT+CFUN=0", NULL, + cfun_disable, modem, NULL); - chat_disconnect(data->chat); + g_at_chat_shutdown(data->chat); g_at_chat_unref(data->chat); data->chat = NULL; |