mirror of git://git.sysmocom.de/ofono
atmodem: Check for auto activated contexts during init
To detect if a context gets activated before we register for unsolicited events we need to check if any is already activated, and flag it auto activated.
This commit is contained in:
parent
1107d3cbc3
commit
cfac75a332
|
@ -43,6 +43,7 @@
|
|||
|
||||
static const char *cgreg_prefix[] = { "+CGREG:", NULL };
|
||||
static const char *cgdcont_prefix[] = { "+CGDCONT:", NULL };
|
||||
static const char *cgact_prefix[] = { "+CGACT:", NULL };
|
||||
static const char *none_prefix[] = { NULL };
|
||||
|
||||
struct gprs_data {
|
||||
|
@ -192,6 +193,48 @@ static void at_cgdcont_read_cb(gboolean ok, GAtResult *result,
|
|||
activated_cid);
|
||||
}
|
||||
|
||||
static void at_cgact_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
||||
{
|
||||
struct ofono_gprs *gprs = user_data;
|
||||
struct gprs_data *gd = ofono_gprs_get_data(gprs);
|
||||
GAtResultIter iter;
|
||||
|
||||
DBG("ok %d", ok);
|
||||
|
||||
if (!ok) {
|
||||
ofono_warn("Can't read CGACT contexts.");
|
||||
return;
|
||||
}
|
||||
|
||||
g_at_result_iter_init(&iter, result);
|
||||
|
||||
while (g_at_result_iter_next(&iter, "+CGACT:")) {
|
||||
int read_cid = -1;
|
||||
int read_status = -1;
|
||||
|
||||
if (!g_at_result_iter_next_number(&iter, &read_cid))
|
||||
break;
|
||||
|
||||
if (!g_at_result_iter_next_number(&iter, &read_status))
|
||||
break;
|
||||
|
||||
if (read_status != 1)
|
||||
continue;
|
||||
|
||||
/* Flag this as auto context as it was obviously active */
|
||||
if (gd->last_auto_context_id == 0)
|
||||
gd->last_auto_context_id = read_cid;
|
||||
|
||||
if (read_cid != gd->last_auto_context_id)
|
||||
continue;
|
||||
|
||||
g_at_chat_send(gd->chat, "AT+CGDCONT?", cgdcont_prefix,
|
||||
at_cgdcont_read_cb, gprs, NULL);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void cgreg_notify(GAtResult *result, gpointer user_data)
|
||||
{
|
||||
struct ofono_gprs *gprs = user_data;
|
||||
|
@ -495,6 +538,10 @@ static void gprs_initialized(gboolean ok, GAtResult *result, gpointer user_data)
|
|||
break;
|
||||
}
|
||||
|
||||
/* Check if there is any already activated contexts at init */
|
||||
g_at_chat_send(gd->chat, "AT+CGACT?", cgact_prefix,
|
||||
at_cgact_cb, gprs, NULL);
|
||||
|
||||
ofono_gprs_register(gprs);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue