summaryrefslogtreecommitdiffstats
path: root/plugins/zte.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/zte.c')
-rw-r--r--plugins/zte.c90
1 files changed, 29 insertions, 61 deletions
diff --git a/plugins/zte.c b/plugins/zte.c
index 4bac3cf3..4426b4c6 100644
--- a/plugins/zte.c
+++ b/plugins/zte.c
@@ -23,7 +23,6 @@
#include <config.h>
#endif
-#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@@ -53,8 +52,6 @@ static const char *none_prefix[] = { NULL };
struct zte_data {
GAtChat *modem;
GAtChat *aux;
- struct ofono_gprs *gprs;
- struct ofono_gprs_context *gc;
};
static int zte_probe(struct ofono_modem *modem)
@@ -80,9 +77,6 @@ static void zte_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);
}
@@ -97,8 +91,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);
@@ -114,6 +108,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)
@@ -125,38 +120,20 @@ static GAtChat *open_device(struct ofono_modem *modem,
return chat;
}
-static void zte_disconnect(gpointer user_data)
+static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
{
struct ofono_modem *modem = user_data;
struct zte_data *data = ofono_modem_get_data(modem);
DBG("");
- 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,
- zte_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);
-}
-
-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);
}
@@ -171,9 +148,6 @@ static int zte_enable(struct ofono_modem *modem)
if (data->modem == NULL)
return -EINVAL;
- g_at_chat_set_disconnect_function(data->modem,
- zte_disconnect, modem);
-
data->aux = open_device(modem, "Aux", "Aux: ");
if (data->aux == NULL) {
g_at_chat_unref(data->modem);
@@ -181,11 +155,11 @@ static int zte_enable(struct ofono_modem *modem)
return -EIO;
}
- g_at_chat_send(data->aux, "ATE0 +CMEE=1", none_prefix,
- NULL, NULL, NULL);
+ 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);
/* Direct transition 0 -> 4 leaves SIM hosed */
- g_at_chat_send(data->aux, "AT+CFUN=1;+CFUN=4", none_prefix,
+ g_at_chat_send(data->aux, "AT+CFUN=1;+CFUN=4", NULL,
cfun_enable, modem, NULL);
return -EINPROGRESS;
@@ -211,19 +185,16 @@ static int zte_disable(struct ofono_modem *modem)
DBG("%p", modem);
- if (data->modem) {
- 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->modem);
+ g_at_chat_unregister_all(data->modem);
- if (data->aux == NULL)
- return 0;
+ 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=0", none_prefix,
+
+ g_at_chat_send(data->aux, "AT+CFUN=0", NULL,
cfun_disable, modem, NULL);
return -EINPROGRESS;
@@ -243,22 +214,18 @@ static void zte_set_online(struct ofono_modem *modem, ofono_bool_t online,
ofono_modem_online_cb_t cb, void *user_data)
{
struct zte_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");
- if (chat == NULL)
- goto error;
-
- 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;
-error:
- g_free(cbd);
-
CALLBACK_WITH_FAILURE(cb, cbd->data);
+
+ g_free(cbd);
}
static void zte_pre_sim(struct ofono_modem *modem)
@@ -270,7 +237,7 @@ static void zte_pre_sim(struct ofono_modem *modem)
ofono_devinfo_create(modem, 0, "atmodem", data->aux);
sim = ofono_sim_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
- "atmodem", data->aux);
+ "atmodem", data->aux);
if (sim)
ofono_sim_inserted_notify(sim, TRUE);
@@ -279,6 +246,8 @@ static void zte_pre_sim(struct ofono_modem *modem)
static void zte_post_sim(struct ofono_modem *modem)
{
struct zte_data *data = ofono_modem_get_data(modem);
+ struct ofono_gprs *gprs;
+ struct ofono_gprs_context *gc;
DBG("%p", modem);
@@ -287,12 +256,11 @@ static void zte_post_sim(struct ofono_modem *modem)
ofono_sms_create(modem, OFONO_VENDOR_QUALCOMM_MSM,
"atmodem", data->aux);
- data->gprs = ofono_gprs_create(modem, 0, "atmodem", data->aux);
-
- data->gc = ofono_gprs_context_create(modem, 0, "atmodem", data->modem);
+ gprs = ofono_gprs_create(modem, 0, "atmodem", data->aux);
+ gc = ofono_gprs_context_create(modem, 0, "atmodem", data->modem);
- if (data->gprs && data->gc)
- ofono_gprs_add_context(data->gprs, data->gc);
+ if (gprs && gc)
+ ofono_gprs_add_context(gprs, gc);
}
static void zte_post_online(struct ofono_modem *modem)