diff options
| author | Michael Biebl <biebl@debian.org> | 2023-08-09 21:55:35 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2023-08-09 21:55:35 +0200 |
| commit | 05e4a733f2141995181a551854d5df929f084adf (patch) | |
| tree | 83bb937740a6667525ba0df046748ecaa829c269 /src/libnm-core-impl/nm-setting-gsm.c | |
| parent | 14b0f3a9dc9ea90d60a3b057350fd4d637dc021a (diff) | |
New upstream version 1.44.0 upstream/1.44.0
Diffstat (limited to 'src/libnm-core-impl/nm-setting-gsm.c')
| -rw-r--r-- | src/libnm-core-impl/nm-setting-gsm.c | 186 |
1 files changed, 141 insertions, 45 deletions
diff --git a/src/libnm-core-impl/nm-setting-gsm.c b/src/libnm-core-impl/nm-setting-gsm.c index 3fe5dfa1..4dde515a 100644 --- a/src/libnm-core-impl/nm-setting-gsm.c +++ b/src/libnm-core-impl/nm-setting-gsm.c @@ -36,7 +36,9 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_AUTO_CONFIG, PROP_DEVICE_ID, PROP_SIM_ID, PROP_SIM_OPERATOR_ID, - PROP_MTU, ); + PROP_MTU, + PROP_INITIAL_EPS_CONFIG, + PROP_INITIAL_EPS_APN, ); typedef struct { char *number; @@ -48,11 +50,13 @@ typedef struct { char *apn; char *network_id; char *pin; + char *initial_eps_apn; guint password_flags; guint pin_flags; guint32 mtu; bool auto_config; bool home_only; + bool initial_eps_config; } NMSettingGsmPrivate; /** @@ -286,6 +290,103 @@ nm_setting_gsm_get_mtu(NMSettingGsm *setting) return NM_SETTING_GSM_GET_PRIVATE(setting)->mtu; } +/** + * nm_setting_gsm_get_initial_eps_config: + * @setting: the #NMSettingGsm + * + * Returns: the #NMSettingGsm:initial-eps-bearer-configure property of the setting + * + * Since: 1.44 + **/ +gboolean +nm_setting_gsm_get_initial_eps_config(NMSettingGsm *setting) +{ + g_return_val_if_fail(NM_IS_SETTING_GSM(setting), FALSE); + + return NM_SETTING_GSM_GET_PRIVATE(setting)->initial_eps_config; +} + +/** + * nm_setting_gsm_get_initial_eps_apn: + * @setting: the #NMSettingGsm + * + * Returns: the #NMSettingGsm:initial-eps-bearer-apn property of the setting + * + * Since: 1.44 + **/ +const char * +nm_setting_gsm_get_initial_eps_apn(NMSettingGsm *setting) +{ + g_return_val_if_fail(NM_IS_SETTING_GSM(setting), NULL); + + return NM_SETTING_GSM_GET_PRIVATE(setting)->initial_eps_apn; +} + +static gboolean +_verify_apn(const char *apn, gboolean allow_empty, const char *property_name, GError **error) +{ + gsize apn_len; + gsize i; + + if (!apn) + return TRUE; + + apn_len = strlen(apn); + + if (!allow_empty && apn_len == 0) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("property value is empty")); + g_prefix_error(error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, property_name); + return FALSE; + } + + if (apn_len > 64) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("property value is too long (>64)")); + g_prefix_error(error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, property_name); + return FALSE; + } + + /* APNs roughly follow the same rules as DNS domain names. Allowed + * characters are a-z, 0-9, . and -. GSM 03.03 Section 9.1 states: + * + * The syntax of the APN shall follow the Name Syntax defined in + * RFC 2181 [14] and RFC 1035 [15]. The APN consists of one or + * more labels. Each label is coded as one octet length field + * followed by that number of octets coded as 8 bit ASCII characters. + * Following RFC 1035 [15] the labels should consist only of the + * alphabetic characters (A-Z and a-z), digits (0-9) and the + * dash (-). The case of alphabetic characters is not significant. + * + * A dot (.) is commonly used to separate parts of the APN, and + * apparently the underscore (_) is used as well. RFC 2181 indicates + * that no restrictions of any kind are placed on DNS labels, and thus + * it would appear that none are placed on APNs either, but many modems + * and networks will fail to accept APNs that include odd characters + * like space ( ) and such. + */ + for (i = 0; i < apn_len; i++) { + if (g_ascii_isalnum(apn[i])) + continue; + if (NM_IN_SET(apn[i], '.', '_', '-')) + continue; + + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("'%s' contains invalid char(s) (use [A-Za-z._-])"), + apn); + g_prefix_error(error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, property_name); + return FALSE; + } + + return TRUE; +} + static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { @@ -300,51 +401,11 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return FALSE; } - if (priv->apn) { - gsize apn_len = strlen(priv->apn); - gsize i; - - if (apn_len > 64) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("property value '%s' is empty or too long (>64)"), - priv->apn); - g_prefix_error(error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_APN); - return FALSE; - } + if (!_verify_apn(priv->apn, TRUE, NM_SETTING_GSM_APN, error)) + return FALSE; - /* APNs roughly follow the same rules as DNS domain names. Allowed - * characters are a-z, 0-9, . and -. GSM 03.03 Section 9.1 states: - * - * The syntax of the APN shall follow the Name Syntax defined in - * RFC 2181 [14] and RFC 1035 [15]. The APN consists of one or - * more labels. Each label is coded as one octet length field - * followed by that number of octets coded as 8 bit ASCII characters. - * Following RFC 1035 [15] the labels should consist only of the - * alphabetic characters (A-Z and a-z), digits (0-9) and the - * dash (-). The case of alphabetic characters is not significant. - * - * A dot (.) is commonly used to separate parts of the APN, and - * apparently the underscore (_) is used as well. RFC 2181 indicates - * that no restrictions of any kind are placed on DNS labels, and thus - * it would appear that none are placed on APNs either, but many modems - * and networks will fail to accept APNs that include odd characters - * like space ( ) and such. - */ - for (i = 0; i < apn_len; i++) { - if (!g_ascii_isalnum(priv->apn[i]) && (priv->apn[i] != '.') && (priv->apn[i] != '_') - && (priv->apn[i] != '-')) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("'%s' contains invalid char(s) (use [A-Za-z._-])"), - priv->apn); - g_prefix_error(error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_APN); - return FALSE; - } - } - } + if (!_verify_apn(priv->initial_eps_apn, FALSE, NM_SETTING_GSM_INITIAL_EPS_BEARER_APN, error)) + return FALSE; if (priv->username && priv->username[0] == '\0') { g_set_error_literal(error, @@ -742,6 +803,41 @@ nm_setting_gsm_class_init(NMSettingGsmClass *klass) NMSettingGsmPrivate, mtu); + /** + * NMSettingGsm:initial-eps-bearer-configure: + * + * For LTE modems, this setting determines whether the initial EPS bearer + * shall be configured when bringing up the connection. It is inferred TRUE + * if initial-eps-bearer-apn is set. + * + * Since: 1.44 + **/ + _nm_setting_property_define_direct_boolean(properties_override, + obj_properties, + NM_SETTING_GSM_INITIAL_EPS_BEARER_CONFIGURE, + PROP_INITIAL_EPS_CONFIG, + FALSE, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + initial_eps_config); + + /** + * NMSettingGsm:initial-eps-bearer-apn: + * + * For LTE modems, this sets the APN for the initial EPS bearer that is set + * up when attaching to the network. Setting this parameter implies + * initial-eps-bearer-configure to be TRUE. + * + * Since: 1.44 + **/ + _nm_setting_property_define_direct_string(properties_override, + obj_properties, + NM_SETTING_GSM_INITIAL_EPS_BEARER_APN, + PROP_INITIAL_EPS_APN, + NM_SETTING_PARAM_NONE, + NMSettingGsmPrivate, + initial_eps_apn); + /* Ignore incoming deprecated properties */ _nm_properties_override_dbus(properties_override, "allowed-bands", |