diff --git a/plugins/ublox.c b/plugins/ublox.c index 20e20567..1a412def 100644 --- a/plugins/ublox.c +++ b/plugins/ublox.c @@ -46,6 +46,7 @@ #include +static const char *uusbconf_prefix[] = { "+UUSBCONF:", NULL }; static const char *none_prefix[] = { NULL }; enum supported_models { @@ -155,6 +156,58 @@ static void cfun_enable(gboolean ok, GAtResult *result, gpointer user_data) ofono_modem_set_powered(modem, TRUE); } +static void query_usbconf_cb(gboolean ok, + GAtResult *result, gpointer user_data) +{ + struct ofono_modem *modem = user_data; + struct ublox_data *data = ofono_modem_get_data(modem); + GAtResultIter iter; + int profile; + + if (!ok) { + ofono_error("Unable to query USB configuration"); + goto error; + } + + g_at_result_iter_init(&iter, result); + +retry: + if (!g_at_result_iter_next(&iter, "+UUSBCONF")) { + ofono_error("Unable to query USB configuration"); + goto error; + } + + if (!g_at_result_iter_next_number(&iter, &profile)) + goto retry; + + switch (profile) { + case 0: /* Fairly back compatible */ + case 1: /* Fairly back compatible plus audio */ + data->model_id = TOBYL2_COMPATIBLE_MODE; + break; + case 2: /* Low/medium throughput */ + data->model_id = TOBYL2_MEDIUM_THROUGHPUT_MODE; + break; + case 3: /* High throughput mode */ + data->model_id = TOBYL2_HIGH_THROUGHPUT_MODE; + break; + default: + ofono_error("Unexpected USB profile: %d", profile); + goto error; + } + + if (g_at_chat_send(data->aux, "AT+CFUN=4", none_prefix, + cfun_enable, modem, NULL)) + return; + +error: + g_at_chat_unref(data->aux); + data->aux = NULL; + g_at_chat_unref(data->modem); + data->modem = NULL; + ofono_modem_set_powered(modem, FALSE); +} + static void query_model_cb(gboolean ok, GAtResult *result, gpointer user_data) { struct ofono_modem *modem = user_data; @@ -162,7 +215,6 @@ static void query_model_cb(gboolean ok, GAtResult *result, gpointer user_data) struct ofono_error error; const char *model; const struct ublox_model *m; - const char *model_str; decode_at_error(&error, g_at_result_final_response(result)); @@ -184,28 +236,13 @@ static void query_model_cb(gboolean ok, GAtResult *result, gpointer user_data) DBG("Model: %s", data->model->name); - if (data->model->flags & UBLOX_F_TOBY_L2) { - model_str = ofono_modem_get_string(modem, "Model"); - if (!model_str) - goto fail; + if (data->model->flags & UBLOX_F_HAVE_USBCONF) { + if (g_at_chat_send(data->aux, "AT+UUSBCONF?", uusbconf_prefix, + query_usbconf_cb, modem, NULL)) + return; - /* - * Toby L2 devices are more complex and special than previously - * supported U-Blox devices. So they need a vendor of their own. - */ - data->model_id = strtoul(model_str, NULL, 10); - - switch (data->model_id) { - case TOBYL2_COMPATIBLE_MODE: - case TOBYL2_HIGH_THROUGHPUT_MODE: - break; - case TOBYL2_MEDIUM_THROUGHPUT_MODE: - DBG("low/medium throughtput profile unsupported"); - break; - default: - DBG("unknown ublox model id %d", data->model_id); - goto fail; - } + ofono_error("Unable to query USB configuration"); + goto fail; } else { data->vendor_family = OFONO_VENDOR_UBLOX; }