gsm: handle allowed mode during Simple.Connect()
This commit is contained in:
@@ -76,12 +76,6 @@ mbm_modem_authenticate (MMModemMbm *self,
|
|||||||
const char *password,
|
const char *password,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
static const char *
|
|
||||||
mbm_simple_get_string_property (GHashTable *properties, const char *name, GError **error);
|
|
||||||
|
|
||||||
static uint
|
|
||||||
mbm_simple_get_uint_property (GHashTable *properties, const char *name, GError **error);
|
|
||||||
|
|
||||||
MMModem *
|
MMModem *
|
||||||
mm_modem_mbm_new (const char *device,
|
mm_modem_mbm_new (const char *device,
|
||||||
const char *driver,
|
const char *driver,
|
||||||
@@ -298,6 +292,25 @@ get_allowed_mode (MMGenericGsm *gsm,
|
|||||||
/* Simple Modem class override functions */
|
/* Simple Modem class override functions */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
mbm_simple_get_string_property (GHashTable *properties, const char *name, GError **error)
|
||||||
|
{
|
||||||
|
GValue *value;
|
||||||
|
|
||||||
|
value = (GValue *) g_hash_table_lookup (properties, name);
|
||||||
|
if (!value)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (G_VALUE_HOLDS_STRING (value))
|
||||||
|
return g_value_get_string (value);
|
||||||
|
|
||||||
|
g_set_error (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||||
|
"Invalid property type for '%s': %s (string expected)",
|
||||||
|
name, G_VALUE_TYPE_NAME (value));
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
simple_connect (MMModemSimple *simple,
|
simple_connect (MMModemSimple *simple,
|
||||||
GHashTable *properties,
|
GHashTable *properties,
|
||||||
@@ -307,29 +320,10 @@ simple_connect (MMModemSimple *simple,
|
|||||||
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (simple);
|
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (simple);
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
MMModemSimple *parent_iface;
|
MMModemSimple *parent_iface;
|
||||||
uint network_mode = 0;
|
|
||||||
|
|
||||||
priv->username = mbm_simple_get_string_property (properties, "username", &info->error);
|
priv->username = mbm_simple_get_string_property (properties, "username", &info->error);
|
||||||
priv->password = mbm_simple_get_string_property (properties, "password", &info->error);
|
priv->password = mbm_simple_get_string_property (properties, "password", &info->error);
|
||||||
|
|
||||||
network_mode = mbm_simple_get_uint_property (properties, "network_mode", &info->error);
|
|
||||||
switch (network_mode) {
|
|
||||||
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_ANY:
|
|
||||||
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_PREFERRED:
|
|
||||||
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_PREFERRED:
|
|
||||||
priv->network_mode = MBM_NETWORK_MODE_ANY;
|
|
||||||
break;
|
|
||||||
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_ONLY:
|
|
||||||
priv->network_mode = MBM_NETWORK_MODE_2G;
|
|
||||||
break;
|
|
||||||
case MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_ONLY:
|
|
||||||
priv->network_mode = MBM_NETWORK_MODE_3G;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
priv->network_mode = MBM_NETWORK_MODE_ANY;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent_iface = g_type_interface_peek_parent (MM_MODEM_SIMPLE_GET_INTERFACE (simple));
|
parent_iface = g_type_interface_peek_parent (MM_MODEM_SIMPLE_GET_INTERFACE (simple));
|
||||||
parent_iface->connect (MM_MODEM_SIMPLE (simple), properties, callback, info);
|
parent_iface->connect (MM_MODEM_SIMPLE (simple), properties, callback, info);
|
||||||
}
|
}
|
||||||
@@ -737,44 +731,6 @@ mbm_modem_authenticate (MMModemMbm *self,
|
|||||||
mbm_auth_done (MM_SERIAL_PORT (primary), NULL, NULL, user_data);
|
mbm_auth_done (MM_SERIAL_PORT (primary), NULL, NULL, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
|
||||||
mbm_simple_get_string_property (GHashTable *properties, const char *name, GError **error)
|
|
||||||
{
|
|
||||||
GValue *value;
|
|
||||||
|
|
||||||
value = (GValue *) g_hash_table_lookup (properties, name);
|
|
||||||
if (!value)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (G_VALUE_HOLDS_STRING (value))
|
|
||||||
return g_value_get_string (value);
|
|
||||||
|
|
||||||
g_set_error (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
|
||||||
"Invalid property type for '%s': %s (string expected)",
|
|
||||||
name, G_VALUE_TYPE_NAME (value));
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint
|
|
||||||
mbm_simple_get_uint_property (GHashTable *properties, const char *name, GError **error)
|
|
||||||
{
|
|
||||||
GValue *value;
|
|
||||||
|
|
||||||
value = (GValue *) g_hash_table_lookup (properties, name);
|
|
||||||
if (!value)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (G_VALUE_HOLDS_UINT (value))
|
|
||||||
return g_value_get_uint (value);
|
|
||||||
|
|
||||||
g_set_error (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
|
||||||
"Invalid property type for '%s': %s (uint expected)",
|
|
||||||
name, G_VALUE_TYPE_NAME (value));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@@ -2922,30 +2922,111 @@ mm_generic_gsm_get_at_port (MMGenericGsm *modem,
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
SIMPLE_STATE_CHECK_PIN = 0,
|
SIMPLE_STATE_CHECK_PIN = 0,
|
||||||
SIMPLE_STATE_ENABLE,
|
SIMPLE_STATE_ENABLE,
|
||||||
|
SIMPLE_STATE_ALLOWED_MODE,
|
||||||
SIMPLE_STATE_REGISTER,
|
SIMPLE_STATE_REGISTER,
|
||||||
SIMPLE_STATE_SET_APN,
|
SIMPLE_STATE_SET_APN,
|
||||||
SIMPLE_STATE_CONNECT,
|
SIMPLE_STATE_CONNECT,
|
||||||
SIMPLE_STATE_DONE
|
SIMPLE_STATE_DONE
|
||||||
} SimpleState;
|
} SimpleState;
|
||||||
|
|
||||||
static const char *
|
/* Looks a value up in the simple connect properties dictionary. If the
|
||||||
simple_get_string_property (MMCallbackInfo *info, const char *name, GError **error)
|
* requested key is not present in the dict, NULL is returned. If the
|
||||||
|
* requested key is present but is not a string, an error is returned.
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
simple_get_property (MMCallbackInfo *info,
|
||||||
|
const char *name,
|
||||||
|
GType expected_type,
|
||||||
|
const char **out_str,
|
||||||
|
guint32 *out_num,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
GHashTable *properties = (GHashTable *) mm_callback_info_get_data (info, "simple-connect-properties");
|
GHashTable *properties = (GHashTable *) mm_callback_info_get_data (info, "simple-connect-properties");
|
||||||
GValue *value;
|
GValue *value;
|
||||||
|
gint foo;
|
||||||
|
|
||||||
|
g_return_val_if_fail (properties != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (name != NULL, FALSE);
|
||||||
|
if (out_str)
|
||||||
|
g_return_val_if_fail (*out_str == NULL, FALSE);
|
||||||
|
|
||||||
value = (GValue *) g_hash_table_lookup (properties, name);
|
value = (GValue *) g_hash_table_lookup (properties, name);
|
||||||
if (!value)
|
if (!value)
|
||||||
return NULL;
|
return FALSE;
|
||||||
|
|
||||||
if (G_VALUE_HOLDS_STRING (value))
|
if ((expected_type == G_TYPE_STRING) && G_VALUE_HOLDS_STRING (value)) {
|
||||||
return g_value_get_string (value);
|
*out_str = g_value_get_string (value);
|
||||||
|
return TRUE;
|
||||||
|
} else if (expected_type == G_TYPE_UINT) {
|
||||||
|
if (G_VALUE_HOLDS_UINT (value)) {
|
||||||
|
*out_num = g_value_get_uint (value);
|
||||||
|
return TRUE;
|
||||||
|
} else if (G_VALUE_HOLDS_INT (value)) {
|
||||||
|
/* handle ints for convenience, but only if they are >= 0 */
|
||||||
|
foo = g_value_get_int (value);
|
||||||
|
if (foo >= 0) {
|
||||||
|
*out_num = (guint) foo;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_set_error (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
g_set_error (error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||||
"Invalid property type for '%s': %s (string expected)",
|
"Invalid property type for '%s': %s (%s expected)",
|
||||||
name, G_VALUE_TYPE_NAME (value));
|
name, G_VALUE_TYPE_NAME (value), g_type_name (expected_type));
|
||||||
|
|
||||||
return NULL;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
simple_get_string_property (MMCallbackInfo *info, const char *name, GError **error)
|
||||||
|
{
|
||||||
|
const char *str = NULL;
|
||||||
|
|
||||||
|
simple_get_property (info, name, G_TYPE_STRING, &str, NULL, error);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
simple_get_uint_property (MMCallbackInfo *info, const char *name, guint32 *out_val, GError **error)
|
||||||
|
{
|
||||||
|
return simple_get_property (info, name, G_TYPE_UINT, NULL, out_val, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
simple_get_allowed_mode (MMCallbackInfo *info,
|
||||||
|
MMModemGsmAllowedMode *out_mode,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
MMModemDeprecatedMode old_mode = MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_ANY;
|
||||||
|
MMModemGsmAllowedMode allowed_mode = MM_MODEM_GSM_ALLOWED_MODE_ANY;
|
||||||
|
GError *tmp_error = NULL;
|
||||||
|
|
||||||
|
/* check for new allowed mode first */
|
||||||
|
if (simple_get_uint_property (info, "allowed_mode", &allowed_mode, &tmp_error)) {
|
||||||
|
if (allowed_mode > MM_MODEM_GSM_ALLOWED_MODE_LAST) {
|
||||||
|
g_set_error (&tmp_error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||||
|
"Invalid allowed mode %d", old_mode);
|
||||||
|
} else {
|
||||||
|
*out_mode = allowed_mode;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
} else if (!tmp_error) {
|
||||||
|
/* and if not, the old allowed mode */
|
||||||
|
if (simple_get_uint_property (info, "network_mode", &old_mode, &tmp_error)) {
|
||||||
|
if (old_mode > MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_LAST) {
|
||||||
|
g_set_error (&tmp_error, MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||||
|
"Invalid allowed mode %d", old_mode);
|
||||||
|
} else {
|
||||||
|
*out_mode = mm_modem_gsm_network_old_mode_to_allowed (old_mode);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
*error = tmp_error;
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -2956,6 +3037,7 @@ simple_state_machine (MMModem *modem, GError *error, gpointer user_data)
|
|||||||
SimpleState state = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "simple-connect-state"));
|
SimpleState state = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "simple-connect-state"));
|
||||||
SimpleState next_state = state;
|
SimpleState next_state = state;
|
||||||
gboolean done = FALSE;
|
gboolean done = FALSE;
|
||||||
|
MMModemGsmAllowedMode allowed_mode;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
info->error = g_error_copy (error);
|
||||||
@@ -2984,9 +3066,20 @@ simple_state_machine (MMModem *modem, GError *error, gpointer user_data)
|
|||||||
}
|
}
|
||||||
/* Fall through if no PIN required */
|
/* Fall through if no PIN required */
|
||||||
case SIMPLE_STATE_ENABLE:
|
case SIMPLE_STATE_ENABLE:
|
||||||
next_state = SIMPLE_STATE_REGISTER;
|
next_state = SIMPLE_STATE_ALLOWED_MODE;
|
||||||
mm_modem_enable (modem, simple_state_machine, info);
|
mm_modem_enable (modem, simple_state_machine, info);
|
||||||
break;
|
break;
|
||||||
|
case SIMPLE_STATE_ALLOWED_MODE:
|
||||||
|
next_state = SIMPLE_STATE_REGISTER;
|
||||||
|
if (simple_get_allowed_mode (info, &allowed_mode, &info->error)) {
|
||||||
|
mm_modem_gsm_network_set_allowed_mode (MM_MODEM_GSM_NETWORK (modem),
|
||||||
|
allowed_mode,
|
||||||
|
simple_state_machine,
|
||||||
|
info);
|
||||||
|
break;
|
||||||
|
} else if (info->error)
|
||||||
|
break;
|
||||||
|
/* otherwise fall through as no allowed mode was sent */
|
||||||
case SIMPLE_STATE_REGISTER:
|
case SIMPLE_STATE_REGISTER:
|
||||||
next_state = SIMPLE_STATE_SET_APN;
|
next_state = SIMPLE_STATE_SET_APN;
|
||||||
str = simple_get_string_property (info, "network_id", &info->error);
|
str = simple_get_string_property (info, "network_id", &info->error);
|
||||||
|
@@ -88,7 +88,9 @@ typedef enum {
|
|||||||
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_ONLY,
|
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_ONLY,
|
||||||
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_ONLY,
|
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_ONLY,
|
||||||
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSUPA,
|
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSUPA,
|
||||||
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSPA
|
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSPA,
|
||||||
|
|
||||||
|
MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_LAST = MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSPA
|
||||||
} MMModemDeprecatedMode;
|
} MMModemDeprecatedMode;
|
||||||
|
|
||||||
#endif /* MM_MODEM_GSM_H */
|
#endif /* MM_MODEM_GSM_H */
|
||||||
|
Reference in New Issue
Block a user