mirror of git://git.sysmocom.de/ofono
Refactor: Initialization code
This commit is contained in:
parent
43256236a0
commit
69c872f400
|
@ -151,85 +151,6 @@ error:
|
||||||
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, -1, data);
|
CALLBACK_WITH_FAILURE(cb, -1, -1, -1, -1, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_cgact_read_cb(gboolean ok, GAtResult *result,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
struct ofono_gprs *gprs = user_data;
|
|
||||||
struct gprs_data *gd = ofono_gprs_get_data(gprs);
|
|
||||||
gint cid, state;
|
|
||||||
GAtResultIter iter;
|
|
||||||
struct ofono_gprs_primary_context *ctx;
|
|
||||||
GSList *l;
|
|
||||||
|
|
||||||
dump_response("cgact_read_cb", ok, result);
|
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while (g_at_result_iter_next(&iter, "+CGACT:")) {
|
|
||||||
if (!g_at_result_iter_next_number(&iter, &cid))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!g_at_result_iter_next_number(&iter, &state))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
l = g_slist_find_custom(gd->contexts, &cid,
|
|
||||||
context_id_compare);
|
|
||||||
if (!l)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ctx = l->data;
|
|
||||||
if (ctx->active != state) {
|
|
||||||
ctx->active = state;
|
|
||||||
|
|
||||||
if (state)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ofono_gprs_deactivated(gprs, ctx->id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cgev_notify(GAtResult *result, gpointer user_data)
|
|
||||||
{
|
|
||||||
struct ofono_gprs *gprs = user_data;
|
|
||||||
struct gprs_data *gd = ofono_gprs_get_data(gprs);
|
|
||||||
GAtResultIter iter;
|
|
||||||
const char *event;
|
|
||||||
|
|
||||||
if (!g_at_result_iter_next(&iter, "+CGEV:"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!g_at_result_iter_next_unquoted_string(&iter, &event))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (g_str_has_prefix(event, "REJECT "))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (g_str_has_prefix(event, "NW REACT ") ||
|
|
||||||
g_str_has_prefix(event, "NW DEACT ") ||
|
|
||||||
g_str_has_prefix(event, "ME DEACT ")) {
|
|
||||||
/* Ask what primary contexts are active now */
|
|
||||||
g_at_chat_send(gd->chat, "AT+CGACT?", cgact_prefix,
|
|
||||||
at_cgact_read_cb, gprs, NULL);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_str_has_prefix(event, "NW DETACH ") ||
|
|
||||||
g_str_has_prefix(event, "ME DETACH ")) {
|
|
||||||
detached(gprs);
|
|
||||||
|
|
||||||
ofono_gprs_detached(gprs);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_str_has_prefix(event, "NW CLASS ") ||
|
|
||||||
g_str_has_prefix(event, "ME CLASS "))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cgreg_notify(GAtResult *result, gpointer user_data)
|
static void cgreg_notify(GAtResult *result, gpointer user_data)
|
||||||
{
|
{
|
||||||
struct ofono_gprs *gprs = user_data;
|
struct ofono_gprs *gprs = user_data;
|
||||||
|
@ -262,71 +183,87 @@ static void cgreg_notify(GAtResult *result, gpointer user_data)
|
||||||
out:
|
out:
|
||||||
ofono_debug("cgreg_notify: %d, %d, %d, %d", status, lac, ci, tech);
|
ofono_debug("cgreg_notify: %d, %d, %d, %d", status, lac, ci, tech);
|
||||||
|
|
||||||
if (status != 1 && status != 5)
|
|
||||||
detached(gprs);
|
|
||||||
|
|
||||||
ofono_gprs_status_notify(gprs, status, lac, ci, tech);
|
ofono_gprs_status_notify(gprs, status, lac, ci, tech);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cgev_notify(GAtResult *result, gpointer user_data)
|
||||||
|
{
|
||||||
|
struct ofono_gprs *gprs = user_data;
|
||||||
|
struct gprs_data *gd = ofono_gprs_get_data(gprs);
|
||||||
|
GAtResultIter iter;
|
||||||
|
const char *event;
|
||||||
|
|
||||||
|
if (!g_at_result_iter_next(&iter, "+CGEV:"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!g_at_result_iter_next_unquoted_string(&iter, &event))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (g_str_has_prefix(event, "NW DETACH ") ||
|
||||||
|
g_str_has_prefix(event, "ME DETACH ")) {
|
||||||
|
ofono_gprs_attach_notify(gprs, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gprs_initialized(gboolean ok, GAtResult *result, gpointer user_data)
|
||||||
|
{
|
||||||
|
struct ofono_gprs *gprs = user_data;
|
||||||
|
struct gprs_data *gd = ofono_gprs_get_data(gprs);
|
||||||
|
|
||||||
|
g_at_chat_register(gd->chat, "+CGEV:", cgev_notify, FALSE, gprs, NULL);
|
||||||
|
g_at_chat_register(gd->chat, "+CGREG:", cgreg_notify, FALSE, gprs, NULL);
|
||||||
|
|
||||||
|
ofono_gprs_register(gprs);
|
||||||
|
}
|
||||||
|
|
||||||
static void at_cgdcont_test_cb(gboolean ok, GAtResult *result,
|
static void at_cgdcont_test_cb(gboolean ok, GAtResult *result,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
struct ofono_gprs *gprs = user_data;
|
struct ofono_gprs *gprs = user_data;
|
||||||
struct gprs_data *gd = ofono_gprs_get_data(gprs);
|
struct gprs_data *gd = ofono_gprs_get_data(gprs);
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
gint range[2];
|
int min, max;
|
||||||
GSList *ranges = NULL;
|
|
||||||
const char *pdp_type;
|
const char *pdp_type;
|
||||||
|
gboolean found = FALSE;
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
g_at_result_iter_init(&iter, result);
|
g_at_result_iter_init(&iter, result);
|
||||||
|
|
||||||
while (g_at_result_iter_next(&iter, "+CGDCONT:")) {
|
while (!found && g_at_result_iter_next(&iter, "+CGDCONT:")) {
|
||||||
if (!g_at_result_iter_open_list(&iter))
|
if (!g_at_result_iter_open_list(&iter))
|
||||||
goto next;
|
continue;
|
||||||
|
|
||||||
while (g_at_result_iter_next_range(&iter, &range[0],
|
if (g_at_result_iter_next_range(&iter, &min, &max) == FALSE)
|
||||||
&range[1]))
|
continue;
|
||||||
ranges = g_slist_prepend(ranges,
|
|
||||||
g_memdup(range, sizeof(range)));
|
|
||||||
|
|
||||||
if (!g_at_result_iter_close_list(&iter))
|
if (!g_at_result_iter_close_list(&iter))
|
||||||
goto next;
|
continue;
|
||||||
|
|
||||||
if (!ranges || range[1] < range[0])
|
|
||||||
goto next;
|
|
||||||
|
|
||||||
if (!g_at_result_iter_next_string(&iter, &pdp_type))
|
if (!g_at_result_iter_next_string(&iter, &pdp_type))
|
||||||
goto next;
|
continue;
|
||||||
|
|
||||||
/* We look for IP PDPs */
|
/* We look for IP PDPs */
|
||||||
if (!strcmp(pdp_type, "IP"))
|
if (!strcmp(pdp_type, "IP"))
|
||||||
break;
|
found = TRUE;
|
||||||
|
|
||||||
next:
|
|
||||||
if (ranges) {
|
|
||||||
g_slist_foreach(ranges, (GFunc) g_free, NULL);
|
|
||||||
g_slist_free(ranges);
|
|
||||||
ranges = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!ranges)
|
|
||||||
|
if (found == FALSE)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
gd->primary_id_range = g_slist_reverse(ranges);
|
ofono_gprs_set_cid_range(gprs, min, max);
|
||||||
|
|
||||||
ofono_debug("gprs_init: registering to notifications");
|
g_at_chat_send(gd->chat, "AT+CGREG=2", none_prefix, NULL, NULL, NULL);
|
||||||
|
g_at_chat_send(gd->chat, "AT+CGAUTO=0", none_prefix, NULL, NULL, NULL);
|
||||||
g_at_chat_register(gd->chat, "+CGEV:", cgev_notify, FALSE, gprs, NULL);
|
g_at_chat_send(gd->chat, "AT+CGEREP=2,1", none_prefix,
|
||||||
g_at_chat_register(gd->chat, "+CGREG:", cgreg_notify, FALSE, gprs, NULL);
|
gprs_initialized, gprs, NULL);
|
||||||
|
|
||||||
ofono_gprs_register(gprs);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
ofono_info("GPRS not supported on this device");
|
||||||
ofono_gprs_remove(gprs);
|
ofono_gprs_remove(gprs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,11 +278,9 @@ static int at_gprs_probe(struct ofono_gprs *gprs,
|
||||||
|
|
||||||
ofono_gprs_set_data(gprs, gd);
|
ofono_gprs_set_data(gprs, gd);
|
||||||
|
|
||||||
g_at_chat_send(chat, "AT+CGREG=2", NULL, NULL, NULL, NULL);
|
|
||||||
g_at_chat_send(chat, "AT+CGAUTO=0", NULL, NULL, NULL, NULL);
|
|
||||||
g_at_chat_send(chat, "AT+CGEREP=2,1", NULL, NULL, NULL, NULL);
|
|
||||||
g_at_chat_send(chat, "AT+CGDCONT=?", cgdcont_prefix,
|
g_at_chat_send(chat, "AT+CGDCONT=?", cgdcont_prefix,
|
||||||
at_cgdcont_test_cb, gprs, NULL);
|
at_cgdcont_test_cb, gprs, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue