summary refs log tree commit diff
path: root/libnm-core/nm-setting-gsm.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2016-01-20 16:26:51 +0100
committerMichael Biebl <biebl@debian.org>2016-01-20 16:26:51 +0100
commit494f296a3baab08522617b24b1f126d8f9a17502 (patch)
treec8ef32fb0dd1c4ff35a0b38e787abb58692de0cd /libnm-core/nm-setting-gsm.c
parent54f6333410ffd570e62717d9e77c5c987175e397 (diff)
Imported Upstream version 1.1.90 upstream/1.1.90
Diffstat (limited to 'libnm-core/nm-setting-gsm.c')
-rw-r--r--libnm-core/nm-setting-gsm.c185
1 files changed, 184 insertions, 1 deletions
diff --git a/libnm-core/nm-setting-gsm.c b/libnm-core/nm-setting-gsm.c
index 36557a25..4bb5ba9f 100644
--- a/libnm-core/nm-setting-gsm.c
+++ b/libnm-core/nm-setting-gsm.c
@@ -23,7 +23,6 @@
 #include "config.h"
 
 #include <string.h>
-#include <glib/gi18n-lib.h>
 
 #include "nm-setting-gsm.h"
 #include "nm-utils.h"
@@ -51,6 +50,11 @@ typedef struct {
 	char *password;
 	NMSettingSecretFlags password_flags;
 
+	/* Restrict connection to certain devices or SIMs */
+	char *device_id;
+	char *sim_id;
+	char *sim_operator_id;
+
 	char *apn; /* NULL for dynamic */
 	char *network_id; /* for manual registration or NULL for automatic */
 
@@ -71,6 +75,9 @@ enum {
 	PROP_PIN,
 	PROP_PIN_FLAGS,
 	PROP_HOME_ONLY,
+	PROP_DEVICE_ID,
+	PROP_SIM_ID,
+	PROP_SIM_OPERATOR_ID,
 
 	LAST_PROP
 };
@@ -214,6 +221,54 @@ nm_setting_gsm_get_home_only (NMSettingGsm *setting)
 	return NM_SETTING_GSM_GET_PRIVATE (setting)->home_only;
 }
 
+/**
+ * nm_setting_gsm_get_device_id:
+ * @setting: the #NMSettingGsm
+ *
+ * Returns: the #NMSettingGsm:device-id property of the setting
+ *
+ * Since: 1.2
+ **/
+const char *
+nm_setting_gsm_get_device_id (NMSettingGsm *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
+
+	return NM_SETTING_GSM_GET_PRIVATE (setting)->device_id;
+}
+
+/**
+ * nm_setting_gsm_get_sim_id:
+ * @setting: the #NMSettingGsm
+ *
+ * Returns: the #NMSettingGsm:sim-id property of the setting
+ *
+ * Since: 1.2
+ **/
+const char *
+nm_setting_gsm_get_sim_id (NMSettingGsm *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
+
+	return NM_SETTING_GSM_GET_PRIVATE (setting)->sim_id;
+}
+
+/**
+ * nm_setting_gsm_get_sim_operator_id:
+ * @setting: the #NMSettingGsm
+ *
+ * Returns: the #NMSettingGsm:sim-operator-id property of the setting
+ *
+ * Since: 1.2
+ **/
+const char *
+nm_setting_gsm_get_sim_operator_id (NMSettingGsm *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
+
+	return NM_SETTING_GSM_GET_PRIVATE (setting)->sim_operator_id;
+}
+
 static gboolean
 verify (NMSetting *setting, NMConnection *connection, GError **error)
 {
@@ -313,9 +368,61 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
 		}
 	}
 
+	if (priv->device_id && !priv->device_id[0]) {
+		g_set_error_literal (error,
+		                     NM_CONNECTION_ERROR,
+		                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
+		                     _("property is empty"));
+		g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_DEVICE_ID);
+		return FALSE;
+	}
+
+	if (priv->sim_id && !priv->sim_id[0]) {
+		g_set_error_literal (error,
+		                     NM_CONNECTION_ERROR,
+		                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
+		                     _("property is empty"));
+		g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_SIM_ID);
+		return FALSE;
+	}
+
+	if (priv->sim_operator_id) {
+		size_t len = strlen (priv->sim_operator_id);
+		const char *p = priv->sim_operator_id;
+
+		if (len == 0 || (len != 5 && len != 6)) {
+			g_set_error_literal (error,
+			                     NM_CONNECTION_ERROR,
+			                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
+			                     _("property is empty or wrong size"));
+			g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_SIM_OPERATOR_ID);
+			return FALSE;
+		}
+
+		while (p && *p) {
+			if (!g_ascii_isdigit (*p++)) {
+				g_set_error_literal (error,
+				                     NM_CONNECTION_ERROR,
+				                     NM_CONNECTION_ERROR_INVALID_PROPERTY,
+				                     _("property must contain only digits"));
+				g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_SIM_OPERATOR_ID);
+				return FALSE;
+			}
+		}
+	}
+
 	return TRUE;
 }
 
+static gboolean
+verify_secrets (NMSetting *setting, NMConnection *connection, GError **error)
+{
+	return _nm_setting_verify_secret_string (NM_SETTING_GSM_GET_PRIVATE (setting)->password,
+	                                         NM_SETTING_GSM_SETTING_NAME,
+	                                         NM_SETTING_GSM_PASSWORD,
+	                                         error);
+}
+
 static GPtrArray *
 need_secrets (NMSetting *setting)
 {
@@ -351,6 +458,9 @@ finalize (GObject *object)
 	g_free (priv->apn);
 	g_free (priv->network_id);
 	g_free (priv->pin);
+	g_free (priv->device_id);
+	g_free (priv->sim_id);
+	g_free (priv->sim_operator_id);
 
 	G_OBJECT_CLASS (nm_setting_gsm_parent_class)->finalize (object);
 }
@@ -402,6 +512,18 @@ set_property (GObject *object, guint prop_id,
 	case PROP_HOME_ONLY:
 		priv->home_only = g_value_get_boolean (value);
 		break;
+	case PROP_DEVICE_ID:
+		g_free (priv->device_id);
+		priv->device_id = g_value_dup_string (value);
+		break;
+	case PROP_SIM_ID:
+		g_free (priv->sim_id);
+		priv->sim_id = g_value_dup_string (value);
+		break;
+	case PROP_SIM_OPERATOR_ID:
+		g_free (priv->sim_operator_id);
+		priv->sim_operator_id = g_value_dup_string (value);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -442,6 +564,15 @@ get_property (GObject *object, guint prop_id,
 	case PROP_HOME_ONLY:
 		g_value_set_boolean (value, nm_setting_gsm_get_home_only (setting));
 		break;
+	case PROP_DEVICE_ID:
+		g_value_set_string (value, nm_setting_gsm_get_device_id (setting));
+		break;
+	case PROP_SIM_ID:
+		g_value_set_string (value, nm_setting_gsm_get_sim_id (setting));
+		break;
+	case PROP_SIM_OPERATOR_ID:
+		g_value_set_string (value, nm_setting_gsm_get_sim_operator_id (setting));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -461,6 +592,7 @@ nm_setting_gsm_class_init (NMSettingGsmClass *setting_class)
 	object_class->get_property = get_property;
 	object_class->finalize     = finalize;
 	parent_class->verify       = verify;
+	parent_class->verify_secrets = verify_secrets;
 	parent_class->need_secrets = need_secrets;
 
 	/* Properties */
@@ -597,6 +729,57 @@ nm_setting_gsm_class_init (NMSettingGsmClass *setting_class)
 		                       G_PARAM_READWRITE |
 		                       G_PARAM_STATIC_STRINGS));
 
+	/**
+	 * NMSettingGsm:device-id:
+	 *
+	 * 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.
+	 *
+	 * Since: 1.2
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_DEVICE_ID,
+		 g_param_spec_string (NM_SETTING_GSM_DEVICE_ID, "", "",
+		                      NULL,
+		                      G_PARAM_READWRITE |
+		                      G_PARAM_STATIC_STRINGS));
+
+	/**
+	 * NMSettingGsm:sim-id:
+	 *
+	 * The SIM card unique identifier (as given by the WWAN management service)
+	 * which this connection applies to.  If given, the connection will apply
+	 * to any device also allowed by #NMSettingGsm:device-id which contains a
+	 * SIM card matching the given identifier.
+	 *
+	 * Since: 1.2
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_SIM_ID,
+		 g_param_spec_string (NM_SETTING_GSM_SIM_ID, "", "",
+		                      NULL,
+		                      G_PARAM_READWRITE |
+		                      G_PARAM_STATIC_STRINGS));
+
+	/**
+	 * NMSettingGsm:sim-operator-id:
+	 *
+	 * A MCC/MNC string like "310260" or "21601" identifying the specific
+	 * mobile network operator which this connection applies to.  If given,
+	 * the connection will apply to any device also allowed by
+	 * #NMSettingGsm:device-id and #NMSettingGsm:sim-id which contains a SIM
+	 * card provisioined by the given operator.
+	 *
+	 * Since: 1.2
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_SIM_OPERATOR_ID,
+		 g_param_spec_string (NM_SETTING_GSM_SIM_OPERATOR_ID, "", "",
+		                      NULL,
+		                      G_PARAM_READWRITE |
+		                      G_PARAM_STATIC_STRINGS));
+
 	/* Ignore incoming deprecated properties */
 	_nm_setting_class_add_dbus_only_property (parent_class, "allowed-bands",
 	                                          G_VARIANT_TYPE_UINT32,