diff options
Diffstat (limited to 'plugins/linktop.c')
-rw-r--r-- | plugins/linktop.c | 110 |
1 files changed, 44 insertions, 66 deletions
diff --git a/plugins/linktop.c b/plugins/linktop.c index dbf26dcf..528d3793 100644 --- a/plugins/linktop.c +++ b/plugins/linktop.c @@ -23,7 +23,6 @@ #include <config.h> #endif -#include <stdio.h> #include <errno.h> #include <stdlib.h> @@ -43,8 +42,8 @@ #include <ofono/ussd.h> #include <ofono/gprs.h> #include <ofono/gprs-context.h> -#include <ofono/phonebook.h> #include <ofono/radio-settings.h> +#include <ofono/phonebook.h> #include <ofono/log.h> #include <drivers/atmodem/atutil.h> @@ -54,8 +53,6 @@ static const char *none_prefix[] = { NULL }; struct linktop_data { GAtChat *modem; GAtChat *aux; - struct ofono_gprs *gprs; - struct ofono_gprs_context *gc; }; static int linktop_probe(struct ofono_modem *modem) @@ -81,9 +78,6 @@ static void linktop_remove(struct ofono_modem *modem) ofono_modem_set_data(modem, NULL); - g_at_chat_unref(data->modem); - g_at_chat_unref(data->aux); - g_free(data); } @@ -98,8 +92,8 @@ static GAtChat *open_device(struct ofono_modem *modem, const char *key, char *debug) { const char *device; - GAtSyntax *syntax; GIOChannel *channel; + GAtSyntax *syntax; GAtChat *chat; device = ofono_modem_get_string(modem, key); @@ -115,6 +109,7 @@ static GAtChat *open_device(struct ofono_modem *modem, 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) @@ -126,38 +121,20 @@ static GAtChat *open_device(struct ofono_modem *modem, return chat; } -static void linktop_disconnect(gpointer user_data) +static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) { struct ofono_modem *modem = user_data; struct linktop_data *data = ofono_modem_get_data(modem); - DBG("%p, data->gc %p", modem, data->gc); - - ofono_gprs_context_remove(data->gc); - - g_at_chat_unref(data->modem); - data->modem = NULL; - - data->modem = open_device(modem, "Modem", "Modem: "); - if (data->modem == NULL) - return; - - g_at_chat_set_disconnect_function(data->modem, - linktop_disconnect, modem); - - ofono_info("Reopened GPRS context channel"); - - data->gc = ofono_gprs_context_create(modem, 0, "atmodem", data->modem); - - if (data->gprs && data->gc) - ofono_gprs_add_context(data->gprs, data->gc); -} + DBG(""); -static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) -{ - struct ofono_modem *modem = user_data; + if (!ok) { + g_at_chat_unref(data->modem); + data->modem = NULL; - DBG(""); + g_at_chat_unref(data->aux); + data->aux = NULL; + } ofono_modem_set_powered(modem, ok); } @@ -168,25 +145,22 @@ static int linktop_enable(struct ofono_modem *modem) DBG("%p", modem); - data->aux = open_device(modem, "Aux", "Aux: "); - if (data->aux == NULL) - return -EIO; - data->modem = open_device(modem, "Modem", "Modem: "); - if (data->modem == NULL) { - g_at_chat_unref(data->aux); - data->aux = NULL; + if (data->modem == NULL) + return -EINVAL; + data->aux = open_device(modem, "Aux", "Aux: "); + if (data->aux == NULL) { + g_at_chat_unref(data->modem); + data->modem = NULL; return -EIO; } - g_at_chat_set_disconnect_function(data->modem, - linktop_disconnect, modem); + g_at_chat_send(data->modem, "ATE0 &C0 +CMEE=1", NULL, NULL, NULL, NULL); + g_at_chat_send(data->aux, "ATE0 &C0 +CMEE=1", NULL, NULL, NULL, NULL); - g_at_chat_send(data->aux, "ATE0 +CMEE=1", none_prefix, - NULL, NULL, NULL); - g_at_chat_send(data->aux, "AT+CFUN=4", none_prefix, - cfun_enable, modem, NULL); + g_at_chat_send(data->aux, "AT+CFUN=4", NULL, + cfun_enable, modem, NULL); return -EINPROGRESS; } @@ -201,9 +175,6 @@ static void cfun_disable(gboolean ok, GAtResult *result, gpointer user_data) g_at_chat_unref(data->aux); data->aux = NULL; - g_at_chat_unref(data->modem); - data->modem = NULL; - if (ok) ofono_modem_set_powered(modem, FALSE); } @@ -214,12 +185,17 @@ static int linktop_disable(struct ofono_modem *modem) DBG("%p", modem); - if (data->aux == NULL) - return 0; + g_at_chat_cancel_all(data->modem); + g_at_chat_unregister_all(data->modem); + + g_at_chat_unref(data->modem); + data->modem = NULL; g_at_chat_cancel_all(data->aux); g_at_chat_unregister_all(data->aux); - g_at_chat_send(data->aux, "AT+CFUN=4", NULL, cfun_disable, modem, NULL); + + g_at_chat_send(data->aux, "AT+CFUN=4", NULL, + cfun_disable, modem, NULL); return -EINPROGRESS; } @@ -238,20 +214,18 @@ static void linktop_set_online(struct ofono_modem *modem, ofono_bool_t online, ofono_modem_online_cb_t cb, void *user_data) { struct linktop_data *data = ofono_modem_get_data(modem); - GAtChat *chat = data->aux; struct cb_data *cbd = cb_data_new(cb, user_data); char const *command = online ? "AT+CFUN=1" : "AT+CFUN=4"; DBG("modem %p %s", modem, online ? "online" : "offline"); - cbd->user = data; - - if (g_at_chat_send(chat, command, NULL, set_online_cb, cbd, g_free)) + if (g_at_chat_send(data->aux, command, none_prefix, + set_online_cb, cbd, g_free) > 0) return; - g_free(cbd); - CALLBACK_WITH_FAILURE(cb, cbd->data); + + g_free(cbd); } static void linktop_pre_sim(struct ofono_modem *modem) @@ -271,12 +245,21 @@ static void linktop_pre_sim(struct ofono_modem *modem) static void linktop_post_sim(struct ofono_modem *modem) { struct linktop_data *data = ofono_modem_get_data(modem); + struct ofono_gprs *gprs; + struct ofono_gprs_context *gc; DBG("%p", modem); - ofono_radio_settings_create(modem, 0, "stemodem", data->aux); ofono_phonebook_create(modem, 0, "atmodem", data->aux); ofono_sms_create(modem, 0, "atmodem", data->aux); + + ofono_radio_settings_create(modem, 0, "stemodem", data->aux); + + gprs = ofono_gprs_create(modem, 0, "atmodem", data->aux); + gc = ofono_gprs_context_create(modem, 0, "atmodem", data->modem); + + if (gprs && gc) + ofono_gprs_add_context(gprs, gc); } static void linktop_post_online(struct ofono_modem *modem) @@ -287,15 +270,10 @@ static void linktop_post_online(struct ofono_modem *modem) DBG("%p", modem); ofono_netreg_create(modem, 0, "atmodem", data->aux); + ofono_cbs_create(modem, 0, "atmodem", data->aux); ofono_ussd_create(modem, 0, "atmodem", data->aux); - data->gprs = ofono_gprs_create(modem, 0, "atmodem", data->aux); - data->gc = ofono_gprs_context_create(modem, 0, "atmodem", data->modem); - - if (data->gprs && data->gc) - ofono_gprs_add_context(data->gprs, data->gc); - mw = ofono_message_waiting_create(modem); if (mw) |