#include <gatchat.h>
static const char *cfun_prefix[] = { "+CFUN:", NULL };
-static const char *creg_prefix[] = { "+CREG:", NULL };
-static const char *cops_prefix[] = { "+COPS:", NULL };
static const char *cind_prefix[] = { "+CIND:", NULL };
+static const char *cops_prefix[] = { "+COPS:", NULL };
+static const char *creg_prefix[] = { "+CREG:", NULL };
+static const char *cgreg_prefix[] = { "+CGREG:", NULL };
struct mbm_data {
GAtChat *chat;
g_at_result_iter_init(&iter, result);
}
+static void cgreg_query(gboolean ok, GAtResult *result,
+ gpointer user_data)
+{
+ struct mbm_data *data = user_data;
+ GAtResultIter iter;
+ int status, mode;
+
+ if (data->network == NULL)
+ return;
+
+ g_at_result_iter_init(&iter, result);
+
+ if (g_at_result_iter_next(&iter, "+CGREG:") == FALSE)
+ return;
+
+ g_at_result_iter_skip_next(&iter);
+ g_at_result_iter_next_number(&iter, &status);
+ g_at_result_iter_skip_next(&iter);
+ g_at_result_iter_skip_next(&iter);
+ g_at_result_iter_next_number(&iter, &mode);
+
+ connman_network_set_uint8(data->network, "Cellular.Mode", mode);
+ connman_network_set_group(data->network, data->imsi);
+}
+
static void enap_query(gboolean ok, GAtResult *result,
gpointer user_data)
{
static void enap_enable(gboolean ok, GAtResult *result,
gpointer user_data)
{
+ struct mbm_data *data = user_data;
GAtResultIter iter;
g_at_result_iter_init(&iter, result);
+
+ g_at_chat_send(data->chat, "AT+CGREG?", cgreg_prefix,
+ cgreg_query, data, NULL);
}
static void enap_disable(gboolean ok, GAtResult *result,
g_at_chat_send(data->chat, "AT+CREG=1",
NULL, NULL, NULL, NULL);
- g_at_chat_send(data->chat, "AT+CGREG=1",
+ g_at_chat_send(data->chat, "AT+CGREG=2",
NULL, NULL, NULL, NULL);
g_at_chat_send(data->chat, "AT+CMER=3,0,0,1",
NULL, NULL, NULL, NULL);
static void cgreg_notifier(GAtResult *result, gpointer user_data)
{
+ struct connman_device *device = user_data;
+ struct mbm_data *data = connman_device_get_data(device);
GAtResultIter iter;
- int status;
+ int status, mode;
+
+ if (data->network == NULL)
+ return;
g_at_result_iter_init(&iter, result);
return;
g_at_result_iter_next_number(&iter, &status);
+ g_at_result_iter_skip_next(&iter);
+ g_at_result_iter_skip_next(&iter);
+ g_at_result_iter_next_number(&iter, &mode);
+
+ connman_network_set_uint8(data->network, "Cellular.Mode", mode);
+ connman_network_set_group(data->network, data->imsi);
}
static void cimi_callback(gboolean ok, GAtResult *result, gpointer user_data);
g_free(cmd);
g_at_chat_send(data->chat, "AT*ENAP=1,1", NULL,
- enap_enable, NULL, NULL);
+ enap_enable, data, NULL);
return 0;
}
DBG("network %p", network);
g_at_chat_send(data->chat, "AT*ENAP=0", NULL,
- enap_disable, NULL, NULL);
+ enap_disable, data, NULL);
return 0;
}