mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-19 12:30:41 +02:00
mobile: consolidate secrets requests into NMDeviceModem
Both old and new ModemManager classes were doing the same thing, so consolidate that into the superclass and save some LoC.
This commit is contained in:
parent
12787f8565
commit
4611aec5c2
4 changed files with 62 additions and 85 deletions
|
|
@ -296,48 +296,35 @@ create_gsm_connect_properties (NMConnection *connection)
|
|||
|
||||
static NMActStageReturn
|
||||
act_stage1_prepare (NMModem *_self,
|
||||
NMActRequest *req,
|
||||
GPtrArray **out_hints,
|
||||
const char **out_setting_name,
|
||||
NMConnection *connection,
|
||||
NMDeviceStateReason *reason)
|
||||
{
|
||||
NMModemBroadband *self = NM_MODEM_BROADBAND (_self);
|
||||
NMConnection *connection;
|
||||
MMModemCapability caps;
|
||||
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
g_clear_object (&self->priv->connect_properties);
|
||||
|
||||
*out_setting_name = nm_connection_need_secrets (connection, out_hints);
|
||||
if (!*out_setting_name) {
|
||||
MMModemCapability caps;
|
||||
|
||||
caps = mm_modem_get_current_capabilities (self->priv->modem_iface);
|
||||
|
||||
g_clear_object (&self->priv->connect_properties);
|
||||
|
||||
if (MODEM_CAPS_3GPP (caps))
|
||||
self->priv->connect_properties = create_gsm_connect_properties (connection);
|
||||
else if (MODEM_CAPS_3GPP2 (caps))
|
||||
self->priv->connect_properties = create_cdma_connect_properties (connection);
|
||||
else {
|
||||
nm_log_warn (LOGD_MB, "(%s) not a mobile broadband modem",
|
||||
nm_modem_get_uid (NM_MODEM (self)));
|
||||
return NM_ACT_STAGE_RETURN_FAILURE;
|
||||
}
|
||||
|
||||
if (!self->priv->simple_iface)
|
||||
self->priv->simple_iface = mm_object_get_modem_simple (self->priv->modem_object);
|
||||
|
||||
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (self->priv->simple_iface), MODEM_CONNECT_TIMEOUT_SECS * 1000);
|
||||
mm_modem_simple_connect (self->priv->simple_iface,
|
||||
self->priv->connect_properties,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)connect_ready,
|
||||
g_object_ref (self));
|
||||
} else {
|
||||
/* NMModem will handle requesting secrets... */
|
||||
caps = mm_modem_get_current_capabilities (self->priv->modem_iface);
|
||||
if (MODEM_CAPS_3GPP (caps))
|
||||
self->priv->connect_properties = create_gsm_connect_properties (connection);
|
||||
else if (MODEM_CAPS_3GPP2 (caps))
|
||||
self->priv->connect_properties = create_cdma_connect_properties (connection);
|
||||
else {
|
||||
nm_log_warn (LOGD_MB, "(%s) not a mobile broadband modem",
|
||||
nm_modem_get_uid (NM_MODEM (self)));
|
||||
return NM_ACT_STAGE_RETURN_FAILURE;
|
||||
}
|
||||
|
||||
if (!self->priv->simple_iface)
|
||||
self->priv->simple_iface = mm_object_get_modem_simple (self->priv->modem_object);
|
||||
|
||||
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (self->priv->simple_iface), MODEM_CONNECT_TIMEOUT_SECS * 1000);
|
||||
mm_modem_simple_connect (self->priv->simple_iface,
|
||||
self->priv->connect_properties,
|
||||
NULL,
|
||||
(GAsyncReadyCallback)connect_ready,
|
||||
g_object_ref (self));
|
||||
|
||||
return NM_ACT_STAGE_RETURN_POSTPONE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -538,33 +538,21 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||
|
||||
static NMActStageReturn
|
||||
act_stage1_prepare (NMModem *modem,
|
||||
NMActRequest *req,
|
||||
GPtrArray **out_hints,
|
||||
const char **out_setting_name,
|
||||
NMConnection *connection,
|
||||
NMDeviceStateReason *reason)
|
||||
{
|
||||
NMModemOld *self = NM_MODEM_OLD (modem);
|
||||
NMModemOldPrivate *priv = NM_MODEM_OLD_GET_PRIVATE (self);
|
||||
NMConnection *connection;
|
||||
gboolean enabled = nm_modem_get_mm_enabled (modem);
|
||||
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
if (priv->connect_properties)
|
||||
g_hash_table_destroy (priv->connect_properties);
|
||||
priv->connect_properties = create_connect_properties (connection);
|
||||
|
||||
*out_setting_name = nm_connection_need_secrets (connection, out_hints);
|
||||
if (!*out_setting_name) {
|
||||
gboolean enabled = nm_modem_get_mm_enabled (modem);
|
||||
|
||||
if (priv->connect_properties)
|
||||
g_hash_table_destroy (priv->connect_properties);
|
||||
priv->connect_properties = create_connect_properties (connection);
|
||||
|
||||
if (enabled)
|
||||
do_connect (self);
|
||||
else
|
||||
do_enable (self);
|
||||
} else {
|
||||
/* NMModem will handle requesting secrets... */
|
||||
}
|
||||
if (enabled)
|
||||
do_connect (self);
|
||||
else
|
||||
do_enable (self);
|
||||
|
||||
return NM_ACT_STAGE_RETURN_POSTPONE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -416,9 +416,7 @@ nm_modem_get_secrets (NMModem *self,
|
|||
|
||||
static NMActStageReturn
|
||||
act_stage1_prepare (NMModem *modem,
|
||||
NMActRequest *req,
|
||||
GPtrArray **out_hints,
|
||||
const char **out_setting_name,
|
||||
NMConnection *connection,
|
||||
NMDeviceStateReason *reason)
|
||||
{
|
||||
*reason = NM_DEVICE_STATE_REASON_UNKNOWN;
|
||||
|
|
@ -435,37 +433,43 @@ nm_modem_act_stage1_prepare (NMModem *self,
|
|||
GPtrArray *hints = NULL;
|
||||
const char *setting_name = NULL;
|
||||
NMSettingsGetSecretsFlags flags = NM_SETTINGS_GET_SECRETS_FLAG_ALLOW_INTERACTION;
|
||||
NMConnection *connection;
|
||||
|
||||
if (priv->act_request)
|
||||
g_object_unref (priv->act_request);
|
||||
priv->act_request = g_object_ref (req);
|
||||
|
||||
ret = NM_MODEM_GET_CLASS (self)->act_stage1_prepare (self,
|
||||
req,
|
||||
&hints,
|
||||
&setting_name,
|
||||
reason);
|
||||
if ((ret == NM_ACT_STAGE_RETURN_POSTPONE) && setting_name) {
|
||||
if (priv->secrets_tries++)
|
||||
flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW;
|
||||
connection = nm_act_request_get_connection (req);
|
||||
g_assert (connection);
|
||||
|
||||
priv->secrets_id = nm_act_request_get_secrets (req,
|
||||
setting_name,
|
||||
flags,
|
||||
hints ? g_ptr_array_index (hints, 0) : NULL,
|
||||
modem_secrets_cb,
|
||||
self);
|
||||
if (priv->secrets_id)
|
||||
g_signal_emit (self, signals[AUTH_REQUESTED], 0);
|
||||
else {
|
||||
*reason = NM_DEVICE_STATE_REASON_NO_SECRETS;
|
||||
ret = NM_ACT_STAGE_RETURN_FAILURE;
|
||||
}
|
||||
|
||||
if (hints)
|
||||
g_ptr_array_free (hints, TRUE);
|
||||
setting_name = nm_connection_need_secrets (connection, &hints);
|
||||
if (!setting_name) {
|
||||
/* Ready to connect */
|
||||
g_assert (!hints);
|
||||
return NM_MODEM_GET_CLASS (self)->act_stage1_prepare (self, connection, reason);
|
||||
}
|
||||
|
||||
/* Secrets required... */
|
||||
if (priv->secrets_tries++)
|
||||
flags |= NM_SETTINGS_GET_SECRETS_FLAG_REQUEST_NEW;
|
||||
|
||||
priv->secrets_id = nm_act_request_get_secrets (req,
|
||||
setting_name,
|
||||
flags,
|
||||
hints ? g_ptr_array_index (hints, 0) : NULL,
|
||||
modem_secrets_cb,
|
||||
self);
|
||||
if (priv->secrets_id) {
|
||||
g_signal_emit (self, signals[AUTH_REQUESTED], 0);
|
||||
ret = NM_ACT_STAGE_RETURN_POSTPONE;
|
||||
} else {
|
||||
*reason = NM_DEVICE_STATE_REASON_NO_SECRETS;
|
||||
ret = NM_ACT_STAGE_RETURN_FAILURE;
|
||||
}
|
||||
|
||||
if (hints)
|
||||
g_ptr_array_free (hints, TRUE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,9 +95,7 @@ typedef struct {
|
|||
GError **error);
|
||||
|
||||
NMActStageReturn (*act_stage1_prepare) (NMModem *modem,
|
||||
NMActRequest *req,
|
||||
GPtrArray **out_hints,
|
||||
const char **out_setting_name,
|
||||
NMConnection *connection,
|
||||
NMDeviceStateReason *reason);
|
||||
|
||||
NMActStageReturn (*static_stage3_ip4_config_start) (NMModem *self,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue