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.
This commit is contained in:
Lubomir Rintel 2019-09-09 20:22:19 +02:00
parent c3012c1de6
commit 0eb4a5dfa7
7 changed files with 94 additions and 4 deletions

View file

@ -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,
),

View file

@ -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.")

View file

@ -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>

View file

@ -1298,6 +1298,29 @@ _normalize_bridge_port_vlan_order (NMConnection *self)
return _nm_setting_bridge_port_sort_vlans (s_port);
}
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)
{
@ -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;

View file

@ -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;
@ -66,6 +69,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);
@ -608,6 +643,21 @@ nm_setting_gsm_class_init (NMSettingGsmClass *klass)
setting_class->verify_secrets = verify_secrets;
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:
*

View file

@ -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);

View file

@ -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;