diff options
-rw-r--r-- | plugins/g1.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/plugins/g1.c b/plugins/g1.c index 5c53a12a..0414f495 100644 --- a/plugins/g1.c +++ b/plugins/g1.c @@ -57,39 +57,14 @@ static void g1_debug(const char *str, void *data) /* Detect hardware, and initialize if found */ static int g1_probe(struct ofono_modem *modem) { - GAtSyntax *syntax; - GAtChat *chat; - const char *device; - DBG(""); - device = ofono_modem_get_string(modem, "Device"); - if (device == NULL) - return -EINVAL; - - syntax = g_at_syntax_new_gsm_permissive(); - chat = g_at_chat_new_from_tty(device, syntax); - g_at_syntax_unref(syntax); - - if (chat == NULL) - return -EIO; - - if (getenv("OFONO_AT_DEBUG") != NULL) - g_at_chat_set_debug(chat, g1_debug, NULL); - - ofono_modem_set_data(modem, chat); - return 0; } static void g1_remove(struct ofono_modem *modem) { - GAtChat *chat = ofono_modem_get_data(modem); - DBG(""); - - ofono_modem_set_data(modem, NULL); - g_at_chat_unref(chat); } static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data) @@ -105,10 +80,28 @@ static void cfun_set_on_cb(gboolean ok, GAtResult *result, gpointer user_data) /* power up hardware */ static int g1_enable(struct ofono_modem *modem) { - GAtChat *chat = ofono_modem_get_data(modem); + GAtSyntax *syntax; + GAtChat *chat; + const char *device; DBG(""); + device = ofono_modem_get_string(modem, "Device"); + if (device == NULL) + return -EINVAL; + + syntax = g_at_syntax_new_gsm_permissive(); + chat = g_at_chat_new_from_tty(device, syntax); + g_at_syntax_unref(syntax); + + if (chat == NULL) + return -EIO; + + if (getenv("OFONO_AT_DEBUG") != NULL) + g_at_chat_set_debug(chat, g1_debug, NULL); + + ofono_modem_set_data(modem, chat); + /* ensure modem is in a known state; verbose on, echo/quiet off */ g_at_chat_send(chat, "ATE0Q0V1", NULL, NULL, NULL, NULL); @@ -137,6 +130,9 @@ static int g1_disable(struct ofono_modem *modem) /* power down modem */ g_at_chat_send(chat, "AT+CFUN=0", NULL, cfun_set_off_cb, modem, NULL); + g_at_chat_unref(chat); + ofono_modem_set_data(modem, NULL); + return 0; } |