summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2019-09-09 20:22:19 +0200
committerLubomir Rintel <lkundrak@v3.sk>2019-09-11 14:32:05 +0200
commit0eb4a5dfa7afeba706649a2b6f6cd579fc30a683 (patch)
tree1633821c7e4f23db22373479e8f28cee142e4b90
parentc3012c1de6e6b73f691ff9e851c7ce3852849691 (diff)
downloadNetworkManager-0eb4a5dfa7afeba706649a2b6f6cd579fc30a683.tar.gz
setting-gsm: add auto-config property
This will make NetworkManager look up APN, username, and password in the Mobile Broadband Provider database. It is mutually exclusive with the apn, username and password properties. If that is the case, the connection will be normalized to auto-config=false. This makes it convenient for the user to turn off the automatism by just setting the apn.
-rw-r--r--clients/common/nm-meta-setting-desc.c3
-rw-r--r--clients/common/settings-docs.h.in1
-rw-r--r--clients/tests/test-client.check-on-disk/test_003.expected10
-rw-r--r--libnm-core/nm-connection.c24
-rw-r--r--libnm-core/nm-setting-gsm.c50
-rw-r--r--libnm-core/nm-setting-gsm.h5
-rw-r--r--libnm/libnm.ver5
7 files changed, 94 insertions, 4 deletions
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index 6451fe3378..40faa485ed 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -5365,6 +5365,9 @@ static const NMMetaPropertyInfo *const property_infos_ETHTOOL[] = {
#undef _CURRENT_NM_META_SETTING_TYPE
#define _CURRENT_NM_META_SETTING_TYPE NM_META_SETTING_TYPE_GSM
static const NMMetaPropertyInfo *const property_infos_GSM[] = {
+ PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_AUTO_CONFIG,
+ .property_type = &_pt_gobject_bool,
+ ),
PROPERTY_INFO_WITH_DESC (NM_SETTING_GSM_NUMBER,
.property_type = &_pt_gobject_string,
),
diff --git a/clients/common/settings-docs.h.in b/clients/common/settings-docs.h.in
index d49331993b..518381077b 100644
--- a/clients/common/settings-docs.h.in
+++ b/clients/common/settings-docs.h.in
@@ -170,6 +170,7 @@
#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH N_("An array of 8 boolean values, where the array index corresponds to the User Priority (0 - 7) and the value indicates whether or not the priority may use all of the bandwidth allocated to its assigned group.")
#define DESCRIBE_DOC_NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS N_("An array of 8 uint values, where the array index corresponds to the User Priority (0 - 7) and the value indicates the traffic class (0 - 7) to which the priority is mapped.")
#define DESCRIBE_DOC_NM_SETTING_GSM_APN N_("The GPRS Access Point Name specifying the APN used when establishing a data session with the GSM-based network. The APN often determines how the user will be billed for their network usage and whether the user has access to the Internet or just a provider-specific walled-garden, so it is important to use the correct APN for the user's mobile broadband plan. The APN may only be composed of the characters a-z, 0-9, ., and - per GSM 03.60 Section 14.9.")
+#define DESCRIBE_DOC_NM_SETTING_GSM_AUTO_CONFIG N_("When TRUE, the settings such as APN, username, or password will default to values that match the network the modem will register to in the Mobile Broadband Provider database.")
#define DESCRIBE_DOC_NM_SETTING_GSM_DEVICE_ID N_("The device unique identifier (as given by the WWAN management service) which this connection applies to. If given, the connection will only apply to the specified device.")
#define DESCRIBE_DOC_NM_SETTING_GSM_HOME_ONLY N_("When TRUE, only connections to the home network will be allowed. Connections to roaming networks will not be made.")
#define DESCRIBE_DOC_NM_SETTING_GSM_MTU N_("If non-zero, only transmit packets of the specified size or smaller, breaking larger packets up into multiple frames.")
diff --git a/clients/tests/test-client.check-on-disk/test_003.expected b/clients/tests/test-client.check-on-disk/test_003.expected
index c8cb4903b5..8bffc5b126 100644
--- a/clients/tests/test-client.check-on-disk/test_003.expected
+++ b/clients/tests/test-client.check-on-disk/test_003.expected
@@ -150,12 +150,12 @@ id
path
uuid
<<<
-size: 4116
+size: 4159
location: clients/tests/test-client.py:911:test_003()/12
cmd: $NMCLI con s con-gsm1
lang: C
returncode: 0
-stdout: 3982 bytes
+stdout: 4025 bytes
>>>
connection.id: con-gsm1
connection.uuid: UUID-con-gsm1-REPLACED-REPLACED-REPL
@@ -228,6 +228,7 @@ serial.bits: 8
serial.parity: even
serial.stopbits: 1
serial.send-delay: 100
+gsm.auto-config: no
gsm.number: --
gsm.username: --
gsm.password: <hidden>
@@ -247,12 +248,12 @@ proxy.pac-url: --
proxy.pac-script: --
<<<
-size: 4145
+size: 4189
location: clients/tests/test-client.py:911:test_003()/13
cmd: $NMCLI con s con-gsm1
lang: pl_PL.UTF-8
returncode: 0
-stdout: 4001 bytes
+stdout: 4045 bytes
>>>
connection.id: con-gsm1
connection.uuid: UUID-con-gsm1-REPLACED-REPLACED-REPL
@@ -325,6 +326,7 @@ serial.bits: 8
serial.parity: even
serial.stopbits: 1
serial.send-delay: 100
+gsm.auto-config: nie
gsm.number: --
gsm.username: --
gsm.password: <hidden>
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index c78e468d71..36600a89c4 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -1299,6 +1299,29 @@ _normalize_bridge_port_vlan_order (NMConnection *self)
}
static gboolean
+_normalize_gsm_auto_config (NMConnection *self)
+{
+ NMSettingGsm *s_gsm;
+
+ s_gsm = nm_connection_get_setting_gsm (self);
+ if (!s_gsm)
+ return FALSE;
+
+ if (!nm_setting_gsm_get_auto_config (s_gsm))
+ return FALSE;
+
+ if ( !nm_setting_gsm_get_apn (s_gsm)
+ && !nm_setting_gsm_get_username (s_gsm)
+ && !nm_setting_gsm_get_password (s_gsm))
+ return FALSE;
+
+ g_object_set (s_gsm,
+ NM_SETTING_GSM_AUTO_CONFIG, FALSE,
+ NULL);
+ return TRUE;
+}
+
+static gboolean
_normalize_required_settings (NMConnection *self)
{
NMSettingBluetooth *s_bt = nm_connection_get_setting_bluetooth (self);
@@ -1614,6 +1637,7 @@ _connection_normalize (NMConnection *connection,
was_modified |= _normalize_sriov_vf_order (connection);
was_modified |= _normalize_bridge_vlan_order (connection);
was_modified |= _normalize_bridge_port_vlan_order (connection);
+ was_modified |= _normalize_gsm_auto_config (connection);
was_modified = !!was_modified;
diff --git a/libnm-core/nm-setting-gsm.c b/libnm-core/nm-setting-gsm.c
index dd5e5ee37a..973120af86 100644
--- a/libnm-core/nm-setting-gsm.c
+++ b/libnm-core/nm-setting-gsm.c
@@ -24,6 +24,7 @@
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
+ PROP_AUTO_CONFIG,
PROP_NUMBER,
PROP_USERNAME,
PROP_PASSWORD,
@@ -40,6 +41,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
+ gboolean auto_config;
+
char *number; /* For dialing, duh */
char *username;
char *password;
@@ -67,6 +70,22 @@ G_DEFINE_TYPE (NMSettingGsm, nm_setting_gsm, NM_TYPE_SETTING)
/*****************************************************************************/
/**
+ * nm_setting_gsm_get_auto_config:
+ * @setting: the #NMSettingGsm
+ *
+ * Returns: the #NMSettingGsm:auto-config property of the setting
+ *
+ * Since: 1.22
+ **/
+gboolean
+nm_setting_gsm_get_auto_config (NMSettingGsm *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_GSM (setting), FALSE);
+
+ return NM_SETTING_GSM_GET_PRIVATE (setting)->auto_config;
+}
+
+/**
* nm_setting_gsm_get_number:
* @setting: the #NMSettingGsm
*
@@ -400,6 +419,16 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
}
+ if ( priv->auto_config
+ && (priv->apn || priv->username || priv->password)) {
+ g_set_error_literal (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_INVALID_PROPERTY,
+ _("can't be enabled when manual configuration is present"));
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_AUTO_CONFIG);
+ return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
+ }
+
return TRUE;
}
@@ -440,6 +469,9 @@ get_property (GObject *object, guint prop_id,
NMSettingGsm *setting = NM_SETTING_GSM (object);
switch (prop_id) {
+ case PROP_AUTO_CONFIG:
+ g_value_set_boolean (value, nm_setting_gsm_get_auto_config (setting));
+ break;
case PROP_NUMBER:
g_value_set_string (value, nm_setting_gsm_get_number (setting));
break;
@@ -493,6 +525,9 @@ set_property (GObject *object, guint prop_id,
char *tmp;
switch (prop_id) {
+ case PROP_AUTO_CONFIG:
+ priv->auto_config = g_value_get_boolean (value);
+ break;
case PROP_NUMBER:
g_free (priv->number);
priv->number = g_value_dup_string (value);
@@ -609,6 +644,21 @@ nm_setting_gsm_class_init (NMSettingGsmClass *klass)
setting_class->need_secrets = need_secrets;
/**
+ * NMSettingGsm:auto-config:
+ *
+ * When %TRUE, the settings such as APN, username, or password will
+ * default to values that match the network the modem will register
+ * to in the Mobile Broadband Provider database.
+ *
+ * Since: 1.22
+ **/
+ obj_properties[PROP_AUTO_CONFIG] =
+ g_param_spec_boolean (NM_SETTING_GSM_AUTO_CONFIG, "", "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+
+ /**
* NMSettingGsm:number:
*
* Legacy setting that used to help establishing PPP data sessions for
diff --git a/libnm-core/nm-setting-gsm.h b/libnm-core/nm-setting-gsm.h
index 057ccf9e75..8a6fabd7f8 100644
--- a/libnm-core/nm-setting-gsm.h
+++ b/libnm-core/nm-setting-gsm.h
@@ -24,6 +24,7 @@ G_BEGIN_DECLS
#define NM_SETTING_GSM_SETTING_NAME "gsm"
+#define NM_SETTING_GSM_AUTO_CONFIG "auto-config"
#define NM_SETTING_GSM_USERNAME "username"
#define NM_SETTING_GSM_PASSWORD "password"
#define NM_SETTING_GSM_PASSWORD_FLAGS "password-flags"
@@ -59,6 +60,10 @@ typedef struct {
GType nm_setting_gsm_get_type (void);
NMSetting *nm_setting_gsm_new (void);
+
+NM_AVAILABLE_IN_1_22
+gboolean nm_setting_gsm_get_auto_config (NMSettingGsm *setting);
+
const char *nm_setting_gsm_get_username (NMSettingGsm *setting);
const char *nm_setting_gsm_get_password (NMSettingGsm *setting);
const char *nm_setting_gsm_get_apn (NMSettingGsm *setting);
diff --git a/libnm/libnm.ver b/libnm/libnm.ver
index 51e0d87241..68eaf745e9 100644
--- a/libnm/libnm.ver
+++ b/libnm/libnm.ver
@@ -1628,3 +1628,8 @@ global:
nm_setting_wireguard_get_ip6_auto_default_route;
nm_settings_add_connection2_flags_get_type;
} libnm_1_18_0;
+
+libnm_1_22_0 {
+global:
+ nm_setting_gsm_get_auto_config;
+} libnm_1_20_0;