From d61e815c7fadf5a3982dac7e4ef0fe316a9cd74f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 18 Feb 2012 13:02:42 +0100 Subject: hso: Open modem port to log extra notifications --- plugins/hso.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'plugins/hso.c') diff --git a/plugins/hso.c b/plugins/hso.c index 4834c56c..497c64e7 100644 --- a/plugins/hso.c +++ b/plugins/hso.c @@ -58,6 +58,7 @@ static const char *opcm_prefix[] = { "_OPCMENABLE:", NULL }; struct hso_data { GAtChat *app; GAtChat *control; + GAtChat *modem; guint sim_poll_source; guint sim_poll_count; ofono_bool_t have_sim; @@ -297,12 +298,20 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) check_model, modem, NULL); } -static GAtChat *create_port(const char *device) +static GAtChat *open_device(struct ofono_modem *modem, + const char *key, char *debug) { - GAtSyntax *syntax; + const char *device; GIOChannel *channel; + GAtSyntax *syntax; GAtChat *chat; + device = ofono_modem_get_string(modem, key); + if (device == NULL) + return NULL; + + DBG("%s %s", key, device); + channel = g_at_tty_open(device, NULL); if (channel == NULL) return NULL; @@ -310,47 +319,36 @@ static GAtChat *create_port(const char *device) syntax = g_at_syntax_new_gsm_permissive(); chat = g_at_chat_new(channel, syntax); g_at_syntax_unref(syntax); + g_io_channel_unref(channel); if (chat == NULL) return NULL; + if (getenv("OFONO_AT_DEBUG")) + g_at_chat_set_debug(chat, hso_debug, debug); + return chat; } static int hso_enable(struct ofono_modem *modem) { struct hso_data *data = ofono_modem_get_data(modem); - const char *app; - const char *control; DBG("%p", modem); - control = ofono_modem_get_string(modem, "ControlPort"); - app = ofono_modem_get_string(modem, "ApplicationPort"); - - if (app == NULL || control == NULL) - return -EINVAL; - - data->control = create_port(control); - + data->control = open_device(modem, "Control", "Control: "); if (data->control == NULL) - return -EIO; - - if (getenv("OFONO_AT_DEBUG")) - g_at_chat_set_debug(data->control, hso_debug, "Control: "); - - data->app = create_port(app); + return -EINVAL; + data->app = open_device(modem, "Application", "App: "); if (data->app == NULL) { g_at_chat_unref(data->control); data->control = NULL; - return -EIO; } - if (getenv("OFONO_AT_DEBUG")) - g_at_chat_set_debug(data->app, hso_debug, "App: "); + data->modem = open_device(modem, "Modem", "Modem: "); g_at_chat_send(data->control, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL); g_at_chat_send(data->app, "ATE0 +CMEE=1", NULL, NULL, NULL, NULL); @@ -387,6 +385,9 @@ static int hso_disable(struct ofono_modem *modem) g_at_chat_cancel_all(data->control); g_at_chat_unregister_all(data->control); + g_at_chat_unref(data->modem); + data->modem = NULL; + g_at_chat_unref(data->app); data->app = NULL; -- cgit v1.2.3