Commit 4325c11f authored by Lubomir Rintel's avatar Lubomir Rintel 🥕

wwan/modem-broadband: look up default APN if GSM conneciton lacks one

This allows the GSM connection to Just Work most of the time, as in:
"nmcli d connect ttyUSB0".
parent b50196e9
Pipeline #43547 failed with stages
in 21 minutes and 38 seconds
......@@ -73,6 +73,9 @@
/* Define to path of the kernel firmware directory */
#mesondefine KERNEL_FIRMWARE_DIR
/* Mobile Broadband Service Provider Information Database location */
#mesondefine MOBILE_BROADBAND_PROVIDER_INFO_DATABASE
/* Path to netconfig */
#mesondefine NETCONFIG_PATH
......
......@@ -753,10 +753,20 @@ if (test "${with_modem_manager_1}" != "no"); then
fi
else
with_modem_manager_1="yes"
PKG_CHECK_MODULES(MOBILE_BROADBAND_PROVIDER_INFO, [mobile-broadband-provider-info],
[MOBILE_BROADBAND_PROVIDER_INFO_DATABASE=`$PKG_CONFIG --variable=database mobile-broadband-provider-info`],
[MOBILE_BROADBAND_PROVIDER_INFO_DATABASE="$prefix/share/mobile-broadband-provider-info/serviceproviders.xml"])
AC_DEFINE_UNQUOTED([MOBILE_BROADBAND_PROVIDER_INFO_DATABASE],
["$MOBILE_BROADBAND_PROVIDER_INFO_DATABASE"],
[Mobile Broadband Service Provider Information Database location])
fi
fi
AM_CONDITIONAL(WITH_MODEM_MANAGER_1, test "${with_modem_manager_1}" = "yes")
# Bluez5 DUN support
PKG_CHECK_MODULES(BLUEZ5, [bluez >= 5], [have_bluez5=yes],[have_bluez5=no])
AC_ARG_ENABLE(bluez5-dun,
......
......@@ -22,6 +22,7 @@ install \
\
ModemManager-devel \
ModemManager-glib-devel \
mobile-broadband-provider-info-devel \
audit-libs-devel \
bash-completion \
bluez-libs-devel \
......
......@@ -219,7 +219,9 @@ BuildRequires: libndp-devel >= 1.0
%if 0%{?with_modem_manager_1}
BuildRequires: ModemManager-glib-devel >= 1.0
%endif
%if %{with nmtui}
%if %{with wwan}
BuildRequires: mobile-broadband-provider-info-devel
%endif
BuildRequires: newt-devel
%endif
BuildRequires: /usr/bin/dbus-launch
......
......@@ -505,6 +505,9 @@ config_h.set10('WITH_PPP', enable_ppp)
enable_modem_manager = get_option('modem_manager')
if enable_modem_manager
mm_glib_dep = dependency('mm-glib', version: '>= 0.7.991')
service_provider_db = dependency('mobile-broadband-provider-info').get_pkgconfig_variable('database')
config_h.set_quoted('MOBILE_BROADBAND_PROVIDER_INFO_DATABASE', service_provider_db)
endif
# Bluez5 DUN support
......
......@@ -2,7 +2,7 @@ sources = files(
'nm-modem-broadband.c',
'nm-modem.c',
'nm-modem-manager.c',
'nm-service-provider.c',
'nm-service-providers.c',
)
deps = [
......
......@@ -20,6 +20,7 @@
#include "nm-default.h"
#include "nm-modem-broadband.h"
#include "nm-service-providers.h"
#include <arpa/inet.h>
#include <libmm-glib.h>
......@@ -274,7 +275,10 @@ create_cdma_connect_properties (NMConnection *connection)
}
static MMSimpleConnectProperties *
create_gsm_connect_properties (NMConnection *connection)
create_gsm_connect_properties (NMConnection *connection, const char *default_apn,
char *default_username, char *default_password,
const char *default_gateway, char *default_auth_method,
const GSList *default_dns)
{
NMSettingGsm *setting;
NMSettingPpp *s_ppp;
......@@ -284,9 +288,12 @@ create_gsm_connect_properties (NMConnection *connection)
setting = nm_connection_get_setting_gsm (connection);
properties = mm_simple_connect_properties_new ();
/* Blank APN ("") means the default subscription APN */
str = nm_setting_gsm_get_apn (setting);
mm_simple_connect_properties_set_apn (properties, str ?: "");
if (!str)
str = default_apn;
if (!str)
return FALSE;
mm_simple_connect_properties_set_apn (properties, str);
str = nm_setting_gsm_get_network_id (setting);
if (str)
......@@ -297,10 +304,14 @@ create_gsm_connect_properties (NMConnection *connection)
mm_simple_connect_properties_set_pin (properties, str);
str = nm_setting_gsm_get_username (setting);
if (!str)
str = default_username;
if (str)
mm_simple_connect_properties_set_user (properties, str);
str = nm_setting_gsm_get_password (setting);
if (!str)
str = default_password;
if (str)
mm_simple_connect_properties_set_password (properties, str);
......@@ -456,6 +467,79 @@ send_pin_ready (MMSim *sim, GAsyncResult *result, NMModemBroadband *self)
connect_context_step (self);
}
static void find_gsm_apn_cb (const char *apn, char *username, char *password,
const char *gateway, char *auth_method, const GSList *dns,
GError *error, gpointer user_data)
{
NMModemBroadband *self = user_data;
NMModemBroadbandPrivate *priv = NM_MODEM_BROADBAND_GET_PRIVATE (self);
ConnectContext *ctx = priv->ctx;
if (error) {
_LOGW ("failed to connect '%s': APN not found: %s",
nm_connection_get_id (ctx->connection), error->message);
nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, NM_DEVICE_STATE_REASON_GSM_APN_FAILED);
connect_context_clear (self);
return;
}
/* Blank APN ("") means the default subscription APN */
ctx->connect_properties = create_gsm_connect_properties (ctx->connection, apn ?: "",
username, password,
gateway, auth_method, dns);
g_assert (ctx->connect_properties);
connect_context_step (self);
}
static gboolean
create_connect_properties (NMModemBroadband *self)
{
NMModemBroadbandPrivate *priv = NM_MODEM_BROADBAND_GET_PRIVATE (self);
ConnectContext *ctx = priv->ctx;
if (MODEM_CAPS_3GPP (ctx->caps)) {
ctx->connect_properties = create_gsm_connect_properties (ctx->connection,
NULL, NULL, NULL,
NULL, NULL, NULL);
if (!ctx->connect_properties) {
gs_unref_object MMModem3gpp *modem_3gpp = NULL;
NMSettingGsm *s_gsm;
const char *network_id = NULL;
s_gsm = nm_connection_get_setting_gsm (ctx->connection);
if (s_gsm)
network_id = nm_setting_gsm_get_network_id (s_gsm);
if (!network_id) {
if (mm_modem_get_state (self->_priv.modem_iface) < MM_MODEM_STATE_REGISTERED)
return FALSE;
modem_3gpp = mm_object_get_modem_3gpp (priv->modem_object);
network_id = mm_modem_3gpp_get_operator_code (modem_3gpp);
}
g_return_val_if_fail (network_id, FALSE);
nm_service_providers_find_gsm_apn (MOBILE_BROADBAND_PROVIDER_INFO_DATABASE,
network_id,
ctx->cancellable,
find_gsm_apn_cb,
self);
}
return TRUE;
} else if (MODEM_CAPS_3GPP2 (ctx->caps)) {
ctx->connect_properties = create_cdma_connect_properties (ctx->connection);
g_assert (ctx->connect_properties);
return TRUE;
} else {
_LOGW ("failed to connect '%s': not a mobile broadband modem",
nm_connection_get_id (ctx->connection));
nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED);
connect_context_clear (self);
}
return TRUE;
}
static void
connect_context_step (NMModemBroadband *self)
{
......@@ -500,22 +584,8 @@ connect_context_step (NMModemBroadband *self)
if (mm_modem_get_state (self->_priv.modem_iface) <= MM_MODEM_STATE_LOCKED)
break;
/* Create core connect properties based on the modem capabilities */
g_assert (!ctx->connect_properties);
if (MODEM_CAPS_3GPP (ctx->caps))
ctx->connect_properties = create_gsm_connect_properties (ctx->connection);
else if (MODEM_CAPS_3GPP2 (ctx->caps))
ctx->connect_properties = create_cdma_connect_properties (ctx->connection);
else {
_LOGW ("failed to connect '%s': not a mobile broadband modem",
nm_connection_get_id (ctx->connection));
nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED);
connect_context_clear (self);
if (!create_connect_properties (self))
break;
}
g_assert (ctx->connect_properties);
/* Build up list of IP types that we need to use in the retries */
ctx->ip_types = nm_modem_get_connection_ip_type (NM_MODEM (self), ctx->connection, &error);
......@@ -534,6 +604,9 @@ connect_context_step (NMModemBroadband *self)
}
/* fall through */
case CONNECT_STEP_CONNECT:
if (!ctx->connect_properties)
break;
if (ctx->ip_types_i < ctx->ip_types->len) {
NMModemIPType current;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment