diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 7b1b3fde5..8a89cc83d 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -187,7 +187,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) static gboolean check_connection_available (NMDevice *device, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device); diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c index 8cad44f5c..ae3059de3 100644 --- a/src/devices/nm-device-bond.c +++ b/src/devices/nm-device-bond.c @@ -78,7 +78,7 @@ is_available (NMDevice *dev) static gboolean check_connection_available (NMDevice *device, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object) { /* Connections are always available because the carrier state is determined diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c index 53d5bef33..92c29387c 100644 --- a/src/devices/nm-device-bridge.c +++ b/src/devices/nm-device-bridge.c @@ -76,7 +76,7 @@ is_available (NMDevice *dev) static gboolean check_connection_available (NMDevice *device, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object) { /* Connections are always available because the carrier state is determined diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 26476dd73..af32e9379 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6927,7 +6927,7 @@ nm_device_connection_is_available (NMDevice *self, } if ( is_default_unmanaged - && NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, FALSE, NULL)) { + && NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, NM_DEVICE_CHECK_CON_AVAILABLE_NONE, NULL)) { /* default-unmanaged devices in UNMANAGED state have no available connections * so we must manually check whether the connection is available here. */ return TRUE; @@ -6935,7 +6935,7 @@ nm_device_connection_is_available (NMDevice *self, if ( for_user_activation_request && NM_DEVICE_GET_CLASS (self)->check_connection_available_has_user_override - && NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, TRUE, NULL)) { + && NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST, NULL)) { /* Connections for an explicit user activation request might only be available after * additional checking. * @@ -6970,7 +6970,7 @@ _try_add_available_connection (NMDevice *self, NMConnection *connection) return FALSE; if (nm_device_check_connection_compatible (self, connection)) { - if (NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, FALSE, NULL)) { + if (NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, NM_DEVICE_CHECK_CON_AVAILABLE_NONE, NULL)) { g_hash_table_add (NM_DEVICE_GET_PRIVATE (self)->available_connections, g_object_ref (connection)); return TRUE; @@ -6988,7 +6988,7 @@ _del_available_connection (NMDevice *self, NMConnection *connection) static gboolean check_connection_available (NMDevice *self, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object) { /* Connections which require a network connection are not available when @@ -7050,7 +7050,7 @@ nm_device_get_available_connections (NMDevice *self, const char *specific_object * compatible with it. */ if ( !specific_object - || NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, FALSE, specific_object)) + || NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, NM_DEVICE_CHECK_CON_AVAILABLE_NONE, specific_object)) g_ptr_array_add (array, connection); } } diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 2a1ac54bb..98fc032f1 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -86,6 +86,19 @@ G_BEGIN_DECLS typedef enum NMActStageReturn NMActStageReturn; +/* These flags affect whether a connection is considered available on a device + * (check_connection_available()). The flags should have the meaning of relaxing + * a condition, so that adding a flag might make a connection available that would + * not be available otherwise. Adding a flag should never make a connection + * not available if it would be available otherwise. */ +typedef enum { + NM_DEVICE_CHECK_CON_AVAILABLE_NONE = 0, + NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST = (1L << 0), + + __NM_DEVICE_CHECK_CON_AVAILABLE_ALL, + NM_DEVICE_CHECK_CON_AVAILABLE_ALL = (((__NM_DEVICE_CHECK_CON_AVAILABLE_ALL - 1) << 1) - 1), +} NMDeviceCheckConAvailableFlags; + struct _NMDevice { GObject parent; }; @@ -138,14 +151,15 @@ typedef struct { * is checked against the object defined by @specific_object, if given. * Returns TRUE if the connection is available; FALSE if not. * - * If @for_user_activation_request, a connection might be considered - * available under additional circumstances. That means, if a connection - * is available for an internal, non-user request, it also must be available - * for an external, user request. + * The passed @flags affect whether a connection is considered + * available or not. Adding more flags, means the connection is + * *more* available. + * + * Specifying @specific_object can only reduce the availability of a connection. */ gboolean (* check_connection_available) (NMDevice *self, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object); gboolean check_connection_available_has_user_override; diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c index 34d181229..bddcdcc61 100644 --- a/src/devices/team/nm-device-team.c +++ b/src/devices/team/nm-device-team.c @@ -84,7 +84,7 @@ is_available (NMDevice *device) static gboolean check_connection_available (NMDevice *device, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object) { /* Connections are always available because the carrier state is determined diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 0f1e7d48e..a17fca991 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -866,7 +866,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) static gboolean check_connection_available (NMDevice *device, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); @@ -877,6 +877,9 @@ check_connection_available (NMDevice *device, s_wifi = nm_connection_get_setting_wireless (connection); g_return_val_if_fail (s_wifi, FALSE); + /* a connection that is available for a certain @specific_object, MUST + * also be available in general (without @specific_object). */ + if (specific_object) { NMAccessPoint *ap; @@ -900,7 +903,7 @@ check_connection_available (NMDevice *device, * activating but the network isn't available let the device recheck * availability. */ - if (nm_setting_wireless_get_hidden (s_wifi) || for_user_activation_request) + if (nm_setting_wireless_get_hidden (s_wifi) || NM_FLAGS_HAS (flags, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST)) return TRUE; /* check if its visible */ diff --git a/src/devices/wimax/nm-device-wimax.c b/src/devices/wimax/nm-device-wimax.c index a7f63fdc9..261118696 100644 --- a/src/devices/wimax/nm-device-wimax.c +++ b/src/devices/wimax/nm-device-wimax.c @@ -334,13 +334,16 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) static gboolean check_connection_available (NMDevice *device, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); const GSList *ns_iter = NULL; NMWimaxNsp *nsp; + /* a connection that is available for a certain @specific_object, MUST + * also be available in general (without @specific_object). */ + if (specific_object) { nsp = get_nsp_by_path (NM_DEVICE_WIMAX (device), specific_object); return nsp ? nm_wimax_nsp_check_compatible (nsp, connection) : FALSE; diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 7046e72b6..f210240cd 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -394,7 +394,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection) static gboolean check_connection_available (NMDevice *device, NMConnection *connection, - gboolean for_user_activation_request, + NMDeviceCheckConAvailableFlags flags, const char *specific_object) { NMDeviceModem *self = NM_DEVICE_MODEM (device);