summaryrefslogtreecommitdiffstats
path: root/gatchat/gsmdial.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-03-25 07:20:03 -0700
committerMarcel Holtmann <marcel@holtmann.org>2010-03-25 07:20:03 -0700
commitada2c7f98628c1dc7bd106bd5d52d65f07c5684d (patch)
tree6676b64ee443685a71226aceaef42e576ac5a3ab /gatchat/gsmdial.c
parent5b656cdf347dcc03eece3f81b58a8ae19e9b20a9 (diff)
downloadofono-ada2c7f98628c1dc7bd106bd5d52d65f07c5684d.tar.bz2
Check modem mode before tyring to change it
Diffstat (limited to 'gatchat/gsmdial.c')
-rw-r--r--gatchat/gsmdial.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/gatchat/gsmdial.c b/gatchat/gsmdial.c
index a18f4862..36c5b5e8 100644
--- a/gatchat/gsmdial.c
+++ b/gatchat/gsmdial.c
@@ -39,6 +39,7 @@
#include <gatppp.h>
static const char *none_prefix[] = { NULL };
+static const char *cfun_prefix[] = { "+CFUN:", NULL };
static const char *cgreg_prefix[] = { "+CGREG:", NULL };
static gchar *option_ip = NULL;
@@ -65,6 +66,7 @@ enum state {
};
static int state = 0;
+static int oldmode = 0;
static void gsmdial_debug(const char *str, void *data)
{
@@ -426,6 +428,29 @@ static void start_dial(gboolean ok, GAtResult *result, gpointer user_data)
register_cb, NULL, NULL);
}
+static void check_mode(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ GAtResultIter iter;
+
+ if (!ok) {
+ g_print("Checking modem mode failed\n");
+ exit(1);
+ }
+
+ g_at_result_iter_init(&iter, result);
+ g_at_result_iter_next(&iter, "+CFUN:");
+ g_at_result_iter_next_number(&iter, &oldmode);
+
+ g_print("Current modem mode is %d\n", oldmode);
+
+ if (oldmode == 1) {
+ start_dial(ok, result, NULL);
+ return;
+ }
+
+ g_at_chat_send(control, "AT+CFUN=1", NULL, start_dial, NULL, NULL);
+}
+
static int open_serial()
{
GAtSyntax *syntax;
@@ -618,7 +643,8 @@ int main(int argc, char **argv)
event_loop = g_main_loop_new(NULL, FALSE);
g_at_chat_send(control, "ATE0Q0V1", NULL, NULL, NULL, NULL);
- g_at_chat_send(control, "AT+CFUN=1", NULL, start_dial, NULL, NULL);
+ g_at_chat_send(control, "AT+CFUN?", cfun_prefix,
+ check_mode, NULL, NULL);
g_main_loop_run(event_loop);
g_source_remove(signal_source);