summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2013-09-03 15:34:56 -0500
committerDan Williams <dcbw@redhat.com>2013-10-31 15:33:57 -0500
commitf4befaab00cb365456b25954c60faecd180e64c5 (patch)
tree57f4dc7e1374029c8e62381afdad383278be90e3
parent8a173e1d7a1e3174027920b8bfb4be1bd37ffb34 (diff)
downloadNetworkManager-f4befaab00cb365456b25954c60faecd180e64c5.tar.gz
core: also check specific object when determining available connections
-rw-r--r--src/devices/nm-device-bt.c4
-rw-r--r--src/devices/nm-device-wifi.c11
-rw-r--r--src/devices/nm-device.c46
-rw-r--r--src/devices/nm-device.h11
-rw-r--r--src/devices/wimax/nm-device-wimax.c26
5 files changed, 89 insertions, 9 deletions
diff --git a/src/devices/nm-device-bt.c b/src/devices/nm-device-bt.c
index 08c0f6dfad..e22c96eee3 100644
--- a/src/devices/nm-device-bt.c
+++ b/src/devices/nm-device-bt.c
@@ -221,7 +221,9 @@ check_connection_compatible (NMDevice *device,
}
static gboolean
-check_connection_available (NMDevice *device, NMConnection *connection)
+check_connection_available (NMDevice *device,
+ NMConnection *connection,
+ const char *specific_object)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
guint32 bt_type;
diff --git a/src/devices/nm-device-wifi.c b/src/devices/nm-device-wifi.c
index e4c16613d9..855c1e7a51 100644
--- a/src/devices/nm-device-wifi.c
+++ b/src/devices/nm-device-wifi.c
@@ -1021,13 +1021,22 @@ check_connection_compatible (NMDevice *device,
static gboolean
-check_connection_available (NMDevice *device, NMConnection *connection)
+check_connection_available (NMDevice *device,
+ NMConnection *connection,
+ const char *specific_object)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
NMSettingWireless *s_wifi;
const char *mode;
GSList *ap_iter = NULL;
+ if (specific_object) {
+ NMAccessPoint *ap;
+
+ ap = get_ap_by_path (NM_DEVICE_WIFI (device), specific_object);
+ return ap ? nm_ap_check_compatible (ap, connection) : FALSE;
+ }
+
s_wifi = nm_connection_get_setting_wireless (connection);
/* Ad-Hoc and AP connections are always available because they may be
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 660e26a59d..7fda6332a7 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -320,7 +320,9 @@ static gboolean nm_device_set_ip6_config (NMDevice *dev,
static gboolean nm_device_activate_ip6_config_commit (gpointer user_data);
-static gboolean check_connection_available (NMDevice *device, NMConnection *connection);
+static gboolean check_connection_available (NMDevice *device,
+ NMConnection *connection,
+ const char *specific_object);
static gboolean spec_match_list (NMDevice *device, const GSList *specs);
@@ -6613,7 +6615,7 @@ _try_add_available_connection (NMDevice *self, NMConnection *connection)
if (nm_device_check_connection_compatible (self, connection, NULL)) {
/* Let subclasses implement additional checks on the connection */
if ( NM_DEVICE_GET_CLASS (self)->check_connection_available
- && NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection)) {
+ && NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, NULL)) {
g_hash_table_insert (NM_DEVICE_GET_PRIVATE (self)->available_connections,
g_object_ref (connection),
@@ -6631,7 +6633,9 @@ _del_available_connection (NMDevice *device, NMConnection *connection)
}
static gboolean
-check_connection_available (NMDevice *device, NMConnection *connection)
+check_connection_available (NMDevice *device,
+ NMConnection *connection,
+ const char *specific_object)
{
/* Default is to assume the connection is available unless a subclass
* overrides this with more specific checks.
@@ -6658,6 +6662,42 @@ nm_device_recheck_available_connections (NMDevice *device)
_signal_available_connections_changed (device);
}
+/**
+ * nm_device_get_available_connections:
+ * @device: the #NMDevice
+ * @specific_object: a specific object path if any
+ *
+ * Returns a list of connections available to activate on the device, taking
+ * into account any device-specific details given by @specific_object (like
+ * WiFi access point path).
+ *
+ * Returns: caller-owned #GPtrArray of #NMConnections
+ */
+GPtrArray *
+nm_device_get_available_connections (NMDevice *device, const char *specific_object)
+{
+ NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
+ GHashTableIter iter;
+ guint num_available;
+ NMConnection *connection = NULL;
+ GPtrArray *array = NULL;
+
+ num_available = g_hash_table_size (priv->available_connections);
+ if (num_available > 0) {
+ array = g_ptr_array_sized_new (num_available);
+ g_hash_table_iter_init (&iter, priv->available_connections);
+ while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL)) {
+ /* If a specific object is given, only include connections that are
+ * compatible with it.
+ */
+ if ( !specific_object
+ || NM_DEVICE_GET_CLASS (device)->check_connection_available (device, connection, specific_object))
+ g_ptr_array_add (array, connection);
+ }
+ }
+ return array;
+}
+
static void
cp_connection_added (NMConnectionProvider *cp, NMConnection *connection, gpointer user_data)
{
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index 9993ec5439..b62f45ddc7 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -140,11 +140,13 @@ typedef struct {
GError **error);
/* Checks whether the connection is likely available to be activated,
- * including any live network information like scan lists. Returns
- * TRUE if the connection is available; FALSE if not.
+ * including any live network information like scan lists. The connection
+ * is checked against the object defined by @specific_object, if given.
+ * Returns TRUE if the connection is available; FALSE if not.
*/
gboolean (* check_connection_available) (NMDevice *self,
- NMConnection *connection);
+ NMConnection *connection,
+ const char *specific_object);
gboolean (* complete_connection) (NMDevice *self,
NMConnection *connection,
@@ -337,6 +339,9 @@ void nm_device_add_pending_action (NMDevice *device, const char *action);
void nm_device_remove_pending_action (NMDevice *device, const char *action);
gboolean nm_device_has_pending_action (NMDevice *device);
+GPtrArray *nm_device_get_available_connections (NMDevice *device,
+ const char *specific_object);
+
G_END_DECLS
/* For testing only */
diff --git a/src/devices/wimax/nm-device-wimax.c b/src/devices/wimax/nm-device-wimax.c
index da92e014c4..0061e79db2 100644
--- a/src/devices/wimax/nm-device-wimax.c
+++ b/src/devices/wimax/nm-device-wimax.c
@@ -261,6 +261,22 @@ get_nsp_by_name (NMDeviceWimax *self, const char *name)
return NULL;
}
+static NMWimaxNsp *
+get_nsp_by_path (NMDeviceWimax *self, const char *path)
+{
+ NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
+ GSList *iter;
+
+ for (iter = priv->nsp_list; iter; iter = iter->next) {
+ NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data);
+
+ if (!g_strcmp0 (nm_wimax_nsp_get_dbus_path (nsp), path))
+ return nsp;
+ }
+
+ return NULL;
+}
+
static gboolean
update_availability (NMDeviceWimax *self, gboolean old_available)
{
@@ -375,10 +391,18 @@ check_connection_compatible (NMDevice *device,
}
static gboolean
-check_connection_available (NMDevice *device, NMConnection *connection)
+check_connection_available (NMDevice *device,
+ NMConnection *connection,
+ const char *specific_object)
{
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device);
const GSList *ns_iter = NULL;
+ NMWimaxNsp *nsp;
+
+ if (specific_object) {
+ nsp = get_nsp_by_path (NM_DEVICE_WIMAX (device), specific_object);
+ return nsp ? nm_wimax_nsp_check_compatible (nsp, connection) : FALSE;
+ }
/* Ensure the connection applies to an NSP in the scan list */
for (ns_iter = priv->nsp_list; ns_iter; ns_iter = ns_iter->next) {