zte: implement allowed mode loading/setting
This commit is contained in:
@@ -32,11 +32,13 @@
|
||||
#include "mm-iface-modem-3gpp.h"
|
||||
#include "mm-broadband-modem-zte.h"
|
||||
|
||||
static void iface_modem_init (MMIfaceModem *iface);
|
||||
static void iface_modem_3gpp_init (MMIfaceModem3gpp *iface);
|
||||
|
||||
static MMIfaceModem3gpp *iface_modem_3gpp_parent;
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMBroadbandModemZte, mm_broadband_modem_zte, MM_TYPE_BROADBAND_MODEM, 0,
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init)
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init));
|
||||
|
||||
struct _MMBroadbandModemZtePrivate {
|
||||
@@ -50,6 +52,196 @@ struct _MMBroadbandModemZtePrivate {
|
||||
GRegex *zend_regex; /* SIM request to Rebuild Main Menu */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Load initial allowed/preferred modes (Modem interface) */
|
||||
|
||||
static gboolean
|
||||
load_allowed_modes_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
MMModemMode *allowed,
|
||||
MMModemMode *preferred,
|
||||
GError **error)
|
||||
{
|
||||
const gchar *response;
|
||||
GMatchInfo *match_info = NULL;
|
||||
GRegex *r;
|
||||
gint cm_mode = -1;
|
||||
gint pref_acq = -1;
|
||||
gboolean result;
|
||||
|
||||
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, error);
|
||||
if (!response)
|
||||
return FALSE;
|
||||
|
||||
r = g_regex_new ("\\+ZSNT:\\s*(\\d),(\\d),(\\d)", G_REGEX_UNGREEDY, 0, error);
|
||||
g_assert (r != NULL);
|
||||
|
||||
result = FALSE;
|
||||
if (!g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, error))
|
||||
goto done;
|
||||
|
||||
if (!mm_get_int_from_match_info (match_info, 1, &cm_mode) ||
|
||||
cm_mode < 0 || cm_mode > 2 ||
|
||||
!mm_get_int_from_match_info (match_info, 3, &pref_acq) ||
|
||||
pref_acq < 0 || pref_acq > 2) {
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Failed to parse the allowed mode response: '%s'",
|
||||
response);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Correctly parsed! */
|
||||
result = TRUE;
|
||||
if (cm_mode == 0) {
|
||||
/* Both 2G and 3G allowed */
|
||||
if (pref_acq == 0) {
|
||||
/* Any allowed */
|
||||
*allowed = (MM_MODEM_MODE_CS | MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
|
||||
*preferred = MM_MODEM_MODE_NONE;
|
||||
} else if (pref_acq == 1) {
|
||||
*allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
|
||||
*preferred = MM_MODEM_MODE_2G;
|
||||
} else if (pref_acq == 2) {
|
||||
*allowed = (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
|
||||
*preferred = MM_MODEM_MODE_3G;
|
||||
} else
|
||||
g_assert_not_reached ();
|
||||
} else if (cm_mode == 1) {
|
||||
/* GSM only */
|
||||
*allowed = MM_MODEM_MODE_2G;
|
||||
*preferred = MM_MODEM_MODE_NONE;
|
||||
} else if (cm_mode == 2) {
|
||||
/* WCDMA only */
|
||||
*allowed = MM_MODEM_MODE_3G;
|
||||
*preferred = MM_MODEM_MODE_NONE;
|
||||
} else
|
||||
g_assert_not_reached ();
|
||||
|
||||
done:
|
||||
if (match_info)
|
||||
g_match_info_free (match_info);
|
||||
if (r)
|
||||
g_regex_unref (r);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
load_allowed_modes (MMIfaceModem *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
||||
"+ZSNT?",
|
||||
3,
|
||||
FALSE,
|
||||
callback,
|
||||
user_data);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Set allowed modes (Modem interface) */
|
||||
|
||||
static gboolean
|
||||
set_allowed_modes_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
||||
}
|
||||
|
||||
static void
|
||||
allowed_mode_update_ready (MMBroadbandModemZte *self,
|
||||
GAsyncResult *res,
|
||||
GSimpleAsyncResult *operation_result)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
|
||||
|
||||
if (error)
|
||||
/* Let the error be critical. */
|
||||
g_simple_async_result_take_error (operation_result, error);
|
||||
else
|
||||
g_simple_async_result_set_op_res_gboolean (operation_result, TRUE);
|
||||
g_simple_async_result_complete (operation_result);
|
||||
g_object_unref (operation_result);
|
||||
}
|
||||
|
||||
static void
|
||||
set_allowed_modes (MMIfaceModem *self,
|
||||
MMModemMode allowed,
|
||||
MMModemMode preferred,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *result;
|
||||
gchar *command;
|
||||
gint cm_mode = -1;
|
||||
gint pref_acq = -1;
|
||||
|
||||
result = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback,
|
||||
user_data,
|
||||
set_allowed_modes);
|
||||
|
||||
/* There is no explicit config for CS connections, we just assume we may
|
||||
* have them as part of 2G when no GPRS is available */
|
||||
if (allowed & MM_MODEM_MODE_CS) {
|
||||
allowed |= MM_MODEM_MODE_2G;
|
||||
allowed &= ~MM_MODEM_MODE_CS;
|
||||
}
|
||||
|
||||
if (allowed == MM_MODEM_MODE_2G) {
|
||||
cm_mode = 1;
|
||||
pref_acq = 0;
|
||||
} else if (allowed == MM_MODEM_MODE_3G) {
|
||||
cm_mode = 2;
|
||||
pref_acq = 0;
|
||||
} else if (allowed == (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G)) {
|
||||
cm_mode = 0;
|
||||
if (preferred == MM_MODEM_MODE_2G)
|
||||
pref_acq = 1;
|
||||
else if (preferred == MM_MODEM_MODE_3G)
|
||||
pref_acq = 2;
|
||||
else /* none preferred, so AUTO */
|
||||
pref_acq = 0;
|
||||
}
|
||||
|
||||
if (cm_mode < 0 || pref_acq < 0) {
|
||||
gchar *allowed_str;
|
||||
gchar *preferred_str;
|
||||
|
||||
allowed_str = mm_modem_mode_build_string_from_mask (allowed);
|
||||
preferred_str = mm_modem_mode_build_string_from_mask (preferred);
|
||||
g_simple_async_result_set_error (result,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Requested mode (allowed: '%s', preferred: '%s') not "
|
||||
"supported by the modem.",
|
||||
allowed_str,
|
||||
preferred_str);
|
||||
g_free (allowed_str);
|
||||
g_free (preferred_str);
|
||||
|
||||
g_simple_async_result_complete_in_idle (result);
|
||||
g_object_unref (result);
|
||||
return;
|
||||
}
|
||||
|
||||
command = g_strdup_printf ("AT+ZSNT=%d,0,%d", cm_mode, pref_acq);
|
||||
mm_base_modem_at_command (
|
||||
MM_BASE_MODEM (self),
|
||||
command,
|
||||
3,
|
||||
FALSE,
|
||||
(GAsyncReadyCallback)allowed_mode_update_ready,
|
||||
result);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Setup/Cleanup unsolicited events (3GPP interface) */
|
||||
|
||||
@@ -266,6 +458,15 @@ finalize (GObject *object)
|
||||
G_OBJECT_CLASS (mm_broadband_modem_zte_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
iface_modem_init (MMIfaceModem *iface)
|
||||
{
|
||||
iface->load_allowed_modes = load_allowed_modes;
|
||||
iface->load_allowed_modes_finish = load_allowed_modes_finish;
|
||||
iface->set_allowed_modes = set_allowed_modes;
|
||||
iface->set_allowed_modes_finish = set_allowed_modes_finish;
|
||||
}
|
||||
|
||||
static void
|
||||
iface_modem_3gpp_init (MMIfaceModem3gpp *iface)
|
||||
{
|
||||
|
Reference in New Issue
Block a user