sierra: Fix disable and enable error handling

This commit is contained in:
Marcel Holtmann 2011-07-27 15:41:37 +02:00
parent 6d9d9558fb
commit 1a23051d0f
1 changed files with 15 additions and 17 deletions

View File

@ -23,7 +23,6 @@
#include <config.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@ -104,6 +103,7 @@ static GAtChat *open_device(struct ofono_modem *modem,
syntax = g_at_syntax_new_gsmv1();
chat = g_at_chat_new(channel, syntax);
g_at_syntax_unref(syntax);
g_io_channel_unref(channel);
if (chat == NULL)
@ -118,9 +118,15 @@ static GAtChat *open_device(struct ofono_modem *modem,
static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data)
{
struct ofono_modem *modem = user_data;
struct sierra_data *data = ofono_modem_get_data(modem);
DBG("");
if (!ok) {
g_at_chat_unref(data->chat);
data->chat = NULL;
}
ofono_modem_set_powered(modem, ok);
}
@ -134,7 +140,7 @@ static int sierra_enable(struct ofono_modem *modem)
if (data->chat == NULL)
return -EINVAL;
g_at_chat_send(data->chat, "ATE0 +CMEE=1", none_prefix,
g_at_chat_send(data->chat, "ATE0 &C0 +CMEE=1", NULL,
NULL, NULL, NULL);
g_at_chat_send(data->chat, "AT+CFUN=4", none_prefix,
@ -163,9 +169,6 @@ static int sierra_disable(struct ofono_modem *modem)
DBG("%p", modem);
if (data->chat == NULL)
return 0;
g_at_chat_cancel_all(data->chat);
g_at_chat_unregister_all(data->chat);
@ -179,11 +182,10 @@ static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
struct cb_data *cbd = user_data;
ofono_modem_online_cb_t cb = cbd->cb;
struct ofono_error error;
if (ok)
CALLBACK_WITH_SUCCESS(cb, cbd->data);
else
CALLBACK_WITH_FAILURE(cb, cbd->data);
decode_at_error(&error, g_at_result_final_response(result));
cb(&error, cbd->data);
}
static void sierra_set_online(struct ofono_modem *modem, ofono_bool_t online,
@ -195,17 +197,13 @@ static void sierra_set_online(struct ofono_modem *modem, ofono_bool_t online,
DBG("modem %p %s", modem, online ? "online" : "offline");
if (data->chat == NULL)
goto error;
if (g_at_chat_send(data->chat, command, NULL,
set_online_cb, cbd, g_free))
if (g_at_chat_send(data->chat, 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 sierra_pre_sim(struct ofono_modem *modem)