diff options
| author | Michael Biebl <biebl@debian.org> | 2017-05-11 14:55:55 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2017-05-11 14:55:55 +0200 |
| commit | c333f062ddcba9b35330647bf6cbd0a07f2d786e (patch) | |
| tree | 257c3a0c74c09f4ad2328eab5b932806405f0c1c /src/devices/wwan | |
| parent | a222e56e103f949b148a6942e385ccca2c26d9f3 (diff) | |
New upstream version 1.8.0 upstream/1.8.0
Diffstat (limited to 'src/devices/wwan')
| -rw-r--r-- | src/devices/wwan/libnm-wwan.ver | 1 | ||||
| -rw-r--r-- | src/devices/wwan/nm-device-modem.c | 51 | ||||
| -rw-r--r-- | src/devices/wwan/nm-modem-broadband.c | 34 | ||||
| -rw-r--r-- | src/devices/wwan/nm-modem-ofono.c | 60 | ||||
| -rw-r--r-- | src/devices/wwan/nm-modem.c | 192 | ||||
| -rw-r--r-- | src/devices/wwan/nm-modem.h | 23 |
6 files changed, 215 insertions, 146 deletions
diff --git a/src/devices/wwan/libnm-wwan.ver b/src/devices/wwan/libnm-wwan.ver index 23412de6..eb577aaf 100644 --- a/src/devices/wwan/libnm-wwan.ver +++ b/src/devices/wwan/libnm-wwan.ver @@ -9,6 +9,7 @@ global: nm_modem_deactivate_async_finish; nm_modem_device_state_changed; nm_modem_get_capabilities; + nm_modem_get_configured_mtu; nm_modem_get_control_port; nm_modem_get_data_port; nm_modem_get_driver; diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 7a70a0bf..4a4d2f2c 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -68,10 +68,13 @@ G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE) /*****************************************************************************/ static void -ppp_failed (NMModem *modem, NMDeviceStateReason reason, gpointer user_data) +ppp_failed (NMModem *modem, + guint i_reason, + gpointer user_data) { NMDevice *device = NM_DEVICE (user_data); NMDeviceModem *self = NM_DEVICE_MODEM (user_data); + NMDeviceStateReason reason = i_reason; switch (nm_device_get_state (device)) { case NM_DEVICE_STATE_PREPARE: @@ -110,12 +113,13 @@ ppp_failed (NMModem *modem, NMDeviceStateReason reason, gpointer user_data) static void modem_prepare_result (NMModem *modem, gboolean success, - NMDeviceStateReason reason, + guint i_reason, gpointer user_data) { NMDeviceModem *self = NM_DEVICE_MODEM (user_data); NMDevice *device = NM_DEVICE (self); NMDeviceState state; + NMDeviceStateReason reason = i_reason; state = nm_device_get_state (device); g_return_if_fail (state == NM_DEVICE_STATE_PREPARE); @@ -123,12 +127,12 @@ modem_prepare_result (NMModem *modem, if (success) nm_device_activate_schedule_stage2_device_config (device); else { - if (reason == NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT) { + if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT) { /* If the connect failed because the SIM PIN was wrong don't allow * the device to be auto-activated anymore, which would risk locking * the SIM if the incorrect PIN continues to be used. */ - nm_device_set_autoconnect (device, FALSE); + nm_device_set_autoconnect_intern (device, FALSE); _LOGI (LOGD_MB, "disabling autoconnect due to failed SIM PIN"); } @@ -201,7 +205,7 @@ modem_ip6_config_result (NMModem *modem, NMDeviceModem *self = NM_DEVICE_MODEM (user_data); NMDevice *device = NM_DEVICE (self); NMActStageReturn ret; - NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; + NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; NMIP6Config *ignored = NULL; gboolean got_config = !!config; @@ -235,11 +239,11 @@ modem_ip6_config_result (NMModem *modem, } /* Start SLAAC now that we have a link-local address from the modem */ - ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage3_ip6_config_start (device, &ignored, &reason); + ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage3_ip6_config_start (device, &ignored, &failure_reason); g_assert (ignored == NULL); switch (ret) { case NM_ACT_STAGE_RETURN_FAILURE: - nm_device_ip_method_failed (device, AF_INET6, reason); + nm_device_ip_method_failed (device, AF_INET6, failure_reason); break; case NM_ACT_STAGE_RETURN_IP_FAIL: /* all done */ @@ -371,9 +375,9 @@ device_state_changed (NMDevice *device, nm_modem_state_to_string (nm_modem_get_state (priv->modem))); } - nm_modem_device_state_changed (priv->modem, new_state, old_state, reason); + nm_modem_device_state_changed (priv->modem, new_state, old_state); - switch (reason) { + switch (nm_device_state_reason_check (reason)) { case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED: case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING: case NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED: @@ -386,8 +390,10 @@ device_state_changed (NMDevice *device, /* Block autoconnect of the just-failed connection for situations * where a retry attempt would just fail again. */ - if (connection) - nm_settings_connection_set_autoconnect_blocked_reason (connection, reason); + if (connection) { + nm_settings_connection_set_autoconnect_blocked_reason (connection, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_BLOCKED); + } break; default: break; @@ -509,41 +515,41 @@ deactivate_async (NMDevice *self, /*****************************************************************************/ static NMActStageReturn -act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) +act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) { NMActStageReturn ret; NMActRequest *req; - ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage1_prepare (device, reason); + ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage1_prepare (device, out_failure_reason); if (ret != NM_ACT_STAGE_RETURN_SUCCESS) return ret; req = nm_device_get_act_request (device); - g_assert (req); + g_return_val_if_fail (req, NM_ACT_STAGE_RETURN_FAILURE); - return nm_modem_act_stage1_prepare (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, req, reason); + return nm_modem_act_stage1_prepare (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, req, out_failure_reason); } static NMActStageReturn -act_stage2_config (NMDevice *device, NMDeviceStateReason *reason) +act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) { NMActRequest *req; req = nm_device_get_act_request (device); - g_assert (req); + g_return_val_if_fail (req, NM_ACT_STAGE_RETURN_FAILURE); - return nm_modem_act_stage2_config (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, req, reason); + return nm_modem_act_stage2_config (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, req, out_failure_reason); } static NMActStageReturn act_stage3_ip4_config_start (NMDevice *device, NMIP4Config **out_config, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { return nm_modem_stage3_ip4_config_start (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, device, NM_DEVICE_CLASS (nm_device_modem_parent_class), - reason); + out_failure_reason); } static void @@ -555,11 +561,11 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config) static NMActStageReturn act_stage3_ip6_config_start (NMDevice *device, NMIP6Config **out_config, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { return nm_modem_stage3_ip6_config_start (NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) device)->modem, nm_device_get_act_request (device), - reason); + out_failure_reason); } static gboolean @@ -800,6 +806,7 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass) device_class->owns_iface = owns_iface; device_class->is_available = is_available; device_class->get_ip_iface_identifier = get_ip_iface_identifier; + device_class->get_configured_mtu = nm_modem_get_configured_mtu; device_class->state_changed = device_state_changed; diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index 7dfd38c5..4b16fb14 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -119,7 +119,10 @@ G_DEFINE_TYPE (NMModemBroadband, nm_modem_broadband, NM_TYPE_MODEM) char __prefix_name[128]; \ const char *__uid; \ \ - _nm_log (_level, (_NMLOG_DOMAIN), 0, \ + _nm_log (_level, (_NMLOG_DOMAIN), 0, NULL, \ + ((__self && __self->_priv.ctx) \ + ? nm_connection_get_uuid (__self->_priv.ctx->connection) \ + : NULL), \ "%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ _NMLOG_PREFIX_NAME, \ (__self \ @@ -407,7 +410,7 @@ connect_ready (MMModemSimple *simple_iface, if (ip4_method == NM_MODEM_IP_METHOD_UNKNOWN && ip6_method == NM_MODEM_IP_METHOD_UNKNOWN) { _LOGW ("failed to connect modem: invalid bearer IP configuration"); - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_CONFIG_FAILED); + nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, NM_DEVICE_STATE_REASON_CONFIG_FAILED); connect_context_clear (self); return; } @@ -439,11 +442,10 @@ send_pin_ready (MMSim *sim, GAsyncResult *result, NMModemBroadband *self) if (error) { if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_PIN) || (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED) && - mm_modem_get_unlock_required (self->_priv.modem_iface) == MM_MODEM_LOCK_SIM_PIN)) { + mm_modem_get_unlock_required (self->_priv.modem_iface) == MM_MODEM_LOCK_SIM_PIN)) ask_for_pin (self); - } else { - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, translate_mm_error (self, error)); - } + else + nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, translate_mm_error (self, error)); return; } @@ -506,7 +508,7 @@ connect_context_step (NMModemBroadband *self) _LOGW ("failed to connect '%s': not a mobile broadband modem", nm_connection_get_id (ctx->connection)); - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED); + nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED); connect_context_clear (self); break; } @@ -520,7 +522,7 @@ connect_context_step (NMModemBroadband *self) error->message); g_clear_error (&error); - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED); + nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED); connect_context_clear (self); break; } @@ -559,9 +561,9 @@ connect_context_step (NMModemBroadband *self) /* fall through */ case CONNECT_STEP_LAST: - if (self->_priv.ipv4_config || self->_priv.ipv6_config) { - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, TRUE, NM_DEVICE_STATE_REASON_NONE); - } else { + if (self->_priv.ipv4_config || self->_priv.ipv6_config) + nm_modem_emit_prepare_result (NM_MODEM (self), TRUE, NM_DEVICE_STATE_REASON_NONE); + else { /* If we have a saved error from a previous attempt, use it */ if (!ctx->first_error) ctx->first_error = g_error_new_literal (NM_DEVICE_ERROR, @@ -570,7 +572,7 @@ connect_context_step (NMModemBroadband *self) _LOGW ("failed to connect modem: %s", ctx->first_error->message); - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, translate_mm_error (self, ctx->first_error)); + nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, translate_mm_error (self, ctx->first_error)); } connect_context_clear (self); @@ -581,7 +583,7 @@ connect_context_step (NMModemBroadband *self) static NMActStageReturn act_stage1_prepare (NMModem *_self, NMConnection *connection, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemBroadband *self = NM_MODEM_BROADBAND (_self); @@ -590,7 +592,7 @@ act_stage1_prepare (NMModem *_self, self->_priv.simple_iface = mm_object_get_modem_simple (self->_priv.modem_object); if (!self->_priv.simple_iface) { _LOGW ("cannot access the Simple mobile broadband modem interface"); - *reason = NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED); return NM_ACT_STAGE_RETURN_FAILURE; } } @@ -944,7 +946,7 @@ out: static NMActStageReturn static_stage3_ip4_config_start (NMModem *_self, NMActRequest *req, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemBroadband *self = NM_MODEM_BROADBAND (_self); @@ -1050,7 +1052,7 @@ out: } static NMActStageReturn -stage3_ip6_config_request (NMModem *_self, NMDeviceStateReason *reason) +stage3_ip6_config_request (NMModem *_self, NMDeviceStateReason *out_failure_reason) { NMModemBroadband *self = NM_MODEM_BROADBAND (_self); diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 41d422aa..52b335c7 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -83,7 +83,7 @@ G_DEFINE_TYPE (NMModemOfono, nm_modem_ofono, NM_TYPE_MODEM) char __prefix_name[128]; \ const char *__uid; \ \ - _nm_log (_level, (_NMLOG_DOMAIN), 0, \ + _nm_log (_level, (_NMLOG_DOMAIN), 0, NULL, NULL, \ "%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ _NMLOG_PREFIX_NAME, \ (__self \ @@ -724,8 +724,8 @@ stage1_prepare_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data if (error) { _LOGW ("connection failed: %s", error->message); - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, - NM_DEVICE_STATE_REASON_MODEM_BUSY); + nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, + NM_DEVICE_STATE_REASON_MODEM_BUSY); /* * FIXME: add code to check for InProgress so that the * connection doesn't continue to try and activate, @@ -745,7 +745,6 @@ context_property_changed (GDBusProxy *proxy, { NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; NMPlatformIP4Address addr; gboolean ret = FALSE; GVariant *v_dict; @@ -910,39 +909,40 @@ context_property_changed (GDBusProxy *proxy, out: if (nm_modem_get_state (NM_MODEM (self)) != NM_MODEM_STATE_CONNECTED) { _LOGI ("emitting PREPARE_RESULT: %s", ret ? "TRUE" : "FALSE"); - if (!ret) - reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE; - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, ret, reason); + nm_modem_emit_prepare_result (NM_MODEM (self), ret, + ret + ? NM_DEVICE_STATE_REASON_NONE + : NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); } else { _LOGW ("MODEM_PPP_FAILED"); - g_signal_emit_by_name (self, NM_MODEM_PPP_FAILED, NM_DEVICE_STATE_REASON_PPP_FAILED); + nm_modem_emit_ppp_failed (NM_MODEM (self), NM_DEVICE_STATE_REASON_PPP_FAILED); } } static NMActStageReturn static_stage3_ip4_config_start (NMModem *modem, NMActRequest *req, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemOfono *self = NM_MODEM_OFONO (modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; GError *error = NULL; - if (priv->ip4_config) { - _LOGD ("IP4 config is done; setting modem_state -> CONNECTED"); - g_signal_emit_by_name (self, NM_MODEM_IP4_CONFIG_RESULT, priv->ip4_config, error); + if (!priv->ip4_config) { + _LOGD ("IP4 config not ready(?)"); + return NM_ACT_STAGE_RETURN_FAILURE; + } - /* Signal listener takes ownership of the IP4Config */ - priv->ip4_config = NULL; + _LOGD ("IP4 config is done; setting modem_state -> CONNECTED"); + g_signal_emit_by_name (self, NM_MODEM_IP4_CONFIG_RESULT, priv->ip4_config, error); - nm_modem_set_state (NM_MODEM (self), - NM_MODEM_STATE_CONNECTED, - nm_modem_state_to_string (NM_MODEM_STATE_CONNECTED)); - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } + /* Signal listener takes ownership of the IP4Config */ + priv->ip4_config = NULL; - return ret; + nm_modem_set_state (NM_MODEM (self), + NM_MODEM_STATE_CONNECTED, + nm_modem_state_to_string (NM_MODEM_STATE_CONNECTED)); + return NM_ACT_STAGE_RETURN_POSTPONE; } static void @@ -955,14 +955,14 @@ context_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_dat priv->context_proxy = g_dbus_proxy_new_for_bus_finish (result, &error); if (error) { _LOGE ("failed to create ofono ConnectionContext DBus proxy: %s", error->message); - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, - NM_DEVICE_STATE_REASON_MODEM_BUSY); + nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, + NM_DEVICE_STATE_REASON_MODEM_BUSY); return; } if (!priv->gprs_attached) { - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, - NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER); + nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, + NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER); return; } @@ -1038,7 +1038,7 @@ create_connect_properties (NMConnection *connection) static NMActStageReturn act_stage1_prepare (NMModem *modem, NMConnection *connection, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemOfono *self = NM_MODEM_OFONO (modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); @@ -1047,7 +1047,7 @@ act_stage1_prepare (NMModem *modem, context_id = nm_connection_get_id (connection); id = g_strsplit (context_id, "/", 0); - g_assert (id[2]); + g_return_val_if_fail (id[2], NM_ACT_STAGE_RETURN_FAILURE); _LOGD ("trying %s %s", id[1], id[2]); @@ -1058,8 +1058,8 @@ act_stage1_prepare (NMModem *modem, g_strfreev (id); if (!priv->context_path) { - *reason = NM_DEVICE_STATE_REASON_GSM_APN_FAILED; - return NM_ACT_STAGE_RETURN_FAILURE; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_GSM_APN_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; } if (priv->connect_properties) @@ -1073,7 +1073,7 @@ act_stage1_prepare (NMModem *modem, do_context_activate (self); } else { _LOGW ("could not activate context: modem is not registered."); - *reason = NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER); return NM_ACT_STAGE_RETURN_FAILURE; } diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 1dec0dd1..6494b849 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -33,6 +33,7 @@ #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" #include "nm-route-manager.h" +#include "nm-netns.h" #include "nm-act-request.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" @@ -158,7 +159,7 @@ nm_modem_set_state (NMModem *self, priv->state = new_state; _notify (self, PROP_STATE); - g_signal_emit (self, signals[STATE_CHANGED], 0, (int) new_state, (int) old_state, reason); + g_signal_emit (self, signals[STATE_CHANGED], 0, (int) new_state, (int) old_state); } } @@ -201,7 +202,7 @@ nm_modem_set_mm_enabled (NMModem *self, /* Try to unlock the modem if it's being enabled */ if (enabled) - g_signal_emit_by_name (self, NM_MODEM_AUTH_REQUESTED, 0); + g_signal_emit (self, signals[AUTH_REQUESTED], 0); return; } @@ -222,6 +223,22 @@ nm_modem_emit_removed (NMModem *self) g_signal_emit (self, signals[REMOVED], 0); } +void +nm_modem_emit_prepare_result (NMModem *self, gboolean success, NMDeviceStateReason reason) +{ + nm_assert (NM_IS_MODEM (self)); + + g_signal_emit (self, signals[PREPARE_RESULT], 0, success, (guint) reason); +} + +void +nm_modem_emit_ppp_failed (NMModem *self, NMDeviceStateReason reason) +{ + nm_assert (NM_IS_MODEM (self)); + + g_signal_emit (self, signals[PPP_FAILED], 0, (guint) reason); +} + NMModemIPType nm_modem_get_supported_ip_types (NMModem *self) { @@ -382,10 +399,10 @@ ppp_state_changed (NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_ { switch (status) { case NM_PPP_STATUS_DISCONNECT: - g_signal_emit (NM_MODEM (user_data), signals[PPP_FAILED], 0, NM_DEVICE_STATE_REASON_PPP_DISCONNECT); + nm_modem_emit_ppp_failed (user_data, NM_DEVICE_STATE_REASON_PPP_DISCONNECT); break; case NM_PPP_STATUS_DEAD: - g_signal_emit (NM_MODEM (user_data), signals[PPP_FAILED], 0, NM_DEVICE_STATE_REASON_PPP_FAILED); + nm_modem_emit_ppp_failed (user_data, NM_DEVICE_STATE_REASON_PPP_FAILED); break; default: break; @@ -479,18 +496,19 @@ ppp_ip6_config (NMPPPManager *ppp_manager, static void ppp_stats (NMPPPManager *ppp_manager, - guint32 in_bytes, - guint32 out_bytes, + guint i_in_bytes, + guint i_out_bytes, gpointer user_data) { NMModem *self = NM_MODEM (user_data); NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); + guint32 in_bytes = i_in_bytes; + guint32 out_bytes = i_out_bytes; if (priv->in_bytes != in_bytes || priv->out_bytes != out_bytes) { priv->in_bytes = in_bytes; priv->out_bytes = out_bytes; - - g_signal_emit (self, signals[PPP_STATS], 0, in_bytes, out_bytes); + g_signal_emit (self, signals[PPP_STATS], 0, (guint) in_bytes, (guint) out_bytes); } } @@ -514,18 +532,16 @@ port_speed_is_zero (const char *port) static NMActStageReturn ppp_stage3_ip_config_start (NMModem *self, NMActRequest *req, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); const char *ppp_name = NULL; GError *error = NULL; - NMActStageReturn ret; guint ip_timeout = 30; guint baud_override = 0; g_return_val_if_fail (NM_IS_MODEM (self), NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NM_ACT_STAGE_RETURN_FAILURE); - g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE); /* If we're already running PPP don't restart it; for example, if both * IPv4 and IPv6 are requested, IPv4 gets started first, but we use the @@ -560,24 +576,10 @@ ppp_stage3_ip_config_start (NMModem *self, baud_override = 57600; priv->ppp_manager = nm_ppp_manager_create (priv->data_port, &error); - if ( priv->ppp_manager - && nm_ppp_manager_start (priv->ppp_manager, req, ppp_name, - ip_timeout, baud_override, &error)) { - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, - G_CALLBACK (ppp_state_changed), - self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK (ppp_ip4_config), - self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP6_CONFIG, - G_CALLBACK (ppp_ip6_config), - self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATS, - G_CALLBACK (ppp_stats), - self); - - ret = NM_ACT_STAGE_RETURN_POSTPONE; - } else { + + if ( !priv->ppp_manager + || !nm_ppp_manager_start (priv->ppp_manager, req, ppp_name, + ip_timeout, baud_override, &error)) { nm_log_err (LOGD_PPP, "(%s): error starting PPP: %s", nm_modem_get_uid (self), error->message); @@ -585,11 +587,24 @@ ppp_stage3_ip_config_start (NMModem *self, g_clear_object (&priv->ppp_manager); - *reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED; - ret = NM_ACT_STAGE_RETURN_FAILURE; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; } - return ret; + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, + G_CALLBACK (ppp_state_changed), + self); + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, + G_CALLBACK (ppp_ip4_config), + self); + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP6_CONFIG, + G_CALLBACK (ppp_ip6_config), + self); + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATS, + G_CALLBACK (ppp_stats), + self); + + return NM_ACT_STAGE_RETURN_POSTPONE; } /*****************************************************************************/ @@ -598,7 +613,7 @@ NMActStageReturn nm_modem_stage3_ip4_config_start (NMModem *self, NMDevice *device, NMDeviceClass *device_class, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemPrivate *priv; NMActRequest *req; @@ -611,12 +626,13 @@ nm_modem_stage3_ip4_config_start (NMModem *self, g_return_val_if_fail (NM_IS_MODEM (self), NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (NM_IS_DEVICE (device), NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (NM_IS_DEVICE_CLASS (device_class), NM_ACT_STAGE_RETURN_FAILURE); - g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE); req = nm_device_get_act_request (device); - g_assert (req); + g_return_val_if_fail (req, NM_ACT_STAGE_RETURN_FAILURE); + connection = nm_act_request_get_applied_connection (req); - g_assert (connection); + g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); + method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG); /* Only Disabled and Auto methods make sense for WWAN */ @@ -627,22 +643,22 @@ nm_modem_stage3_ip4_config_start (NMModem *self, nm_log_warn (LOGD_MB | LOGD_IP4, "(%s): unhandled WWAN IPv4 method '%s'; will fail", nm_modem_get_uid (self), method); - *reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); return NM_ACT_STAGE_RETURN_FAILURE; } priv = NM_MODEM_GET_PRIVATE (self); switch (priv->ip4_method) { case NM_MODEM_IP_METHOD_PPP: - ret = ppp_stage3_ip_config_start (self, req, reason); + ret = ppp_stage3_ip_config_start (self, req, out_failure_reason); break; case NM_MODEM_IP_METHOD_STATIC: nm_log_dbg (LOGD_MB, "MODEM_IP_METHOD_STATIC"); - ret = NM_MODEM_GET_CLASS (self)->static_stage3_ip4_config_start (self, req, reason); + ret = NM_MODEM_GET_CLASS (self)->static_stage3_ip4_config_start (self, req, out_failure_reason); break; case NM_MODEM_IP_METHOD_AUTO: nm_log_dbg (LOGD_MB, "MODEM_IP_METHOD_AUTO"); - ret = device_class->act_stage3_ip4_config_start (device, NULL, reason); + ret = device_class->act_stage3_ip4_config_start (device, NULL, out_failure_reason); break; default: nm_log_info (LOGD_MB, "(%s): IPv4 configuration disabled", nm_modem_get_uid (self)); @@ -670,7 +686,7 @@ nm_modem_ip4_pre_commit (NMModem *modem, g_assert (address); if (address->plen == 32) - nm_platform_link_set_noarp (NM_PLATFORM_GET, nm_device_get_ip_ifindex (device)); + nm_platform_link_set_noarp (nm_device_get_platform (device), nm_device_get_ip_ifindex (device)); } } @@ -712,30 +728,28 @@ nm_modem_emit_ip6_config_result (NMModem *self, } static NMActStageReturn -stage3_ip6_config_request (NMModem *self, NMDeviceStateReason *reason) +stage3_ip6_config_request (NMModem *self, NMDeviceStateReason *out_failure_reason) { - *reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); return NM_ACT_STAGE_RETURN_FAILURE; } NMActStageReturn nm_modem_stage3_ip6_config_start (NMModem *self, NMActRequest *req, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemPrivate *priv; NMActStageReturn ret; NMConnection *connection; const char *method; - g_return_val_if_fail (self != NULL, NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (NM_IS_MODEM (self), NM_ACT_STAGE_RETURN_FAILURE); - g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (NM_IS_ACT_REQUEST (req), NM_ACT_STAGE_RETURN_FAILURE); - g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE); connection = nm_act_request_get_applied_connection (req); - g_assert (connection); + g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); + method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG); /* Only Ignore and Auto methods make sense for WWAN */ @@ -746,14 +760,14 @@ nm_modem_stage3_ip6_config_start (NMModem *self, nm_log_warn (LOGD_MB | LOGD_IP6, "(%s): unhandled WWAN IPv6 method '%s'; will fail", nm_modem_get_uid (self), method); - *reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); return NM_ACT_STAGE_RETURN_FAILURE; } priv = NM_MODEM_GET_PRIVATE (self); switch (priv->ip6_method) { case NM_MODEM_IP_METHOD_PPP: - ret = ppp_stage3_ip_config_start (self, req, reason); + ret = ppp_stage3_ip_config_start (self, req, out_failure_reason); break; case NM_MODEM_IP_METHOD_STATIC: case NM_MODEM_IP_METHOD_AUTO: @@ -761,7 +775,7 @@ nm_modem_stage3_ip6_config_start (NMModem *self, * which in the static case is the full config, and the DHCP/Auto case * is just the IPv6LL address to use for SLAAC. */ - ret = NM_MODEM_GET_CLASS (self)->stage3_ip6_config_request (self, reason); + ret = NM_MODEM_GET_CLASS (self)->stage3_ip6_config_request (self, out_failure_reason); break; default: nm_log_info (LOGD_MB, "(%s): IPv6 configuration disabled", nm_modem_get_uid (self)); @@ -772,6 +786,45 @@ nm_modem_stage3_ip6_config_start (NMModem *self, return ret; } +guint32 +nm_modem_get_configured_mtu (NMDevice *self, gboolean *out_is_user_config) +{ + NMConnection *connection; + NMSetting *setting; + gint64 mtu_default; + guint mtu = 0; + const char *property_name; + + nm_assert (NM_IS_DEVICE (self)); + nm_assert (out_is_user_config); + + connection = nm_device_get_applied_connection (self); + if (!connection) + g_return_val_if_reached (0); + + setting = (NMSetting *) nm_connection_get_setting_gsm (connection); + if (!setting) + setting = (NMSetting *) nm_connection_get_setting_cdma (connection); + + if (setting) { + g_object_get (setting, "mtu", &mtu, NULL); + if (mtu) { + *out_is_user_config = TRUE; + return mtu; + } + + property_name = NM_IS_SETTING_GSM (setting) ? "gsm.mtu" : "cdma.mtu"; + mtu_default = nm_device_get_configured_mtu_from_connection_default (self, property_name); + if (mtu_default >= 0) { + *out_is_user_config = TRUE; + return (guint32) mtu_default; + } + } + + *out_is_user_config = FALSE; + return 0; +} + /*****************************************************************************/ static void @@ -835,16 +888,16 @@ nm_modem_get_secrets (NMModem *self, static NMActStageReturn act_stage1_prepare (NMModem *modem, NMConnection *connection, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { - *reason = NM_DEVICE_STATE_REASON_UNKNOWN; + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_UNKNOWN); return NM_ACT_STAGE_RETURN_FAILURE; } NMActStageReturn nm_modem_act_stage1_prepare (NMModem *self, NMActRequest *req, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); gs_unref_ptrarray GPtrArray *hints = NULL; @@ -857,13 +910,13 @@ nm_modem_act_stage1_prepare (NMModem *self, priv->act_request = g_object_ref (req); connection = nm_act_request_get_applied_connection (req); - g_assert (connection); + g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE); 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); + return NM_MODEM_GET_CLASS (self)->act_stage1_prepare (self, connection, out_failure_reason); } /* Secrets required... */ @@ -887,7 +940,7 @@ nm_modem_act_stage1_prepare (NMModem *self, NMActStageReturn nm_modem_act_stage2_config (NMModem *self, NMActRequest *req, - NMDeviceStateReason *reason) + NMDeviceStateReason *out_failure_reason) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); @@ -1016,9 +1069,10 @@ deactivate_cleanup (NMModem *self, NMDevice *device) priv->ip6_method == NM_MODEM_IP_METHOD_AUTO) { ifindex = nm_device_get_ip_ifindex (device); if (ifindex > 0) { - nm_route_manager_route_flush (nm_route_manager_get (), ifindex); - nm_platform_address_flush (NM_PLATFORM_GET, ifindex); - nm_platform_link_set_down (NM_PLATFORM_GET, ifindex); + nm_route_manager_route_flush (nm_netns_get_route_manager (nm_device_get_netns (device)), + ifindex); + nm_platform_address_flush (nm_device_get_platform (device), ifindex); + nm_platform_link_set_down (nm_device_get_platform (device), ifindex); } } } @@ -1205,8 +1259,7 @@ nm_modem_deactivate (NMModem *self, NMDevice *device) void nm_modem_device_state_changed (NMModem *self, NMDeviceState new_state, - NMDeviceState old_state, - NMDeviceStateReason reason) + NMDeviceState old_state) { gboolean was_connected = FALSE, warn = TRUE; NMModemPrivate *priv; @@ -1396,15 +1449,15 @@ set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_PATH: - /* Construct only */ + /* construct-only */ priv->path = g_value_dup_string (value); break; case PROP_DRIVER: - /* Construct only */ + /* construct-only */ priv->driver = g_value_dup_string (value); break; case PROP_CONTROL_PORT: - /* Construct only */ + /* construct-only */ priv->control_port = g_value_dup_string (value); break; case PROP_DATA_PORT: @@ -1412,7 +1465,7 @@ set_property (GObject *object, guint prop_id, priv->data_port = g_value_dup_string (value); break; case PROP_UID: - /* Construct only */ + /* construct-only */ priv->uid = g_value_dup_string (value); break; case PROP_IP4_METHOD: @@ -1628,15 +1681,16 @@ nm_modem_class_init (NMModemClass *klass) g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); signals[PPP_STATS] = - g_signal_new ("ppp-stats", + g_signal_new (NM_MODEM_PPP_STATS, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2, - G_TYPE_UINT, G_TYPE_UINT); + G_TYPE_UINT /*guint32 in_bytes*/, + G_TYPE_UINT /*guint32 out_bytes*/); signals[PPP_FAILED] = - g_signal_new ("ppp-failed", + g_signal_new (NM_MODEM_PPP_FAILED, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, diff --git a/src/devices/wwan/nm-modem.h b/src/devices/wwan/nm-modem.h index c590b9e4..a50727a9 100644 --- a/src/devices/wwan/nm-modem.h +++ b/src/devices/wwan/nm-modem.h @@ -132,17 +132,17 @@ typedef struct { NMActStageReturn (*act_stage1_prepare) (NMModem *modem, NMConnection *connection, - NMDeviceStateReason *reason); + NMDeviceStateReason *out_failure_reason); NMActStageReturn (*static_stage3_ip4_config_start) (NMModem *self, NMActRequest *req, - NMDeviceStateReason *reason); + NMDeviceStateReason *out_failure_reason); /* Request the IP6 config; when the config returns the modem * subclass should emit the ip6_config_result signal. */ NMActStageReturn (*stage3_ip6_config_request) (NMModem *self, - NMDeviceStateReason *reason); + NMDeviceStateReason *out_failure_reason); void (*set_mm_enabled) (NMModem *self, gboolean enabled); @@ -187,20 +187,20 @@ gboolean nm_modem_complete_connection (NMModem *self, NMActStageReturn nm_modem_act_stage1_prepare (NMModem *modem, NMActRequest *req, - NMDeviceStateReason *reason); + NMDeviceStateReason *out_failure_reason); NMActStageReturn nm_modem_act_stage2_config (NMModem *modem, NMActRequest *req, - NMDeviceStateReason *reason); + NMDeviceStateReason *out_failure_reason); NMActStageReturn nm_modem_stage3_ip4_config_start (NMModem *modem, NMDevice *device, NMDeviceClass *device_class, - NMDeviceStateReason *reason); + NMDeviceStateReason *out_failure_reason); NMActStageReturn nm_modem_stage3_ip6_config_start (NMModem *modem, NMActRequest *req, - NMDeviceStateReason *reason); + NMDeviceStateReason *out_failure_reason); void nm_modem_ip4_pre_commit (NMModem *modem, NMDevice *device, NMIP4Config *config); @@ -222,8 +222,7 @@ gboolean nm_modem_deactivate_async_finish (NMModem *self, void nm_modem_device_state_changed (NMModem *modem, NMDeviceState new_state, - NMDeviceState old_state, - NMDeviceStateReason reason); + NMDeviceState old_state); void nm_modem_set_mm_enabled (NMModem *self, gboolean enabled); @@ -239,6 +238,10 @@ NMModemIPType nm_modem_get_supported_ip_types (NMModem *self); /* For the modem-manager only */ void nm_modem_emit_removed (NMModem *self); +void nm_modem_emit_prepare_result (NMModem *self, gboolean success, NMDeviceStateReason reason); + +void nm_modem_emit_ppp_failed (NMModem *self, NMDeviceStateReason reason); + GArray *nm_modem_get_connection_ip_type (NMModem *self, NMConnection *connection, GError **error); @@ -250,4 +253,6 @@ void nm_modem_emit_ip6_config_result (NMModem *self, const gchar *nm_modem_ip_type_to_string (NMModemIPType ip_type); +guint32 nm_modem_get_configured_mtu (NMDevice *self, gboolean *out_is_user_config); + #endif /* __NETWORKMANAGER_MODEM_H__ */ |