diff options
Diffstat (limited to 'src/devices/bluetooth')
| -rw-r--r-- | src/devices/bluetooth/meson.build | 6 | ||||
| -rw-r--r-- | src/devices/bluetooth/nm-bluez-device.c | 94 | ||||
| -rw-r--r-- | src/devices/bluetooth/nm-bluez-manager.c | 4 | ||||
| -rw-r--r-- | src/devices/bluetooth/nm-bluez5-manager.c | 8 | ||||
| -rw-r--r-- | src/devices/bluetooth/nm-device-bt.c | 52 |
5 files changed, 81 insertions, 83 deletions
diff --git a/src/devices/bluetooth/meson.build b/src/devices/bluetooth/meson.build index 30284f9e..019f04f6 100644 --- a/src/devices/bluetooth/meson.build +++ b/src/devices/bluetooth/meson.build @@ -31,10 +31,10 @@ libnm_device_plugin_bluetooth = shared_module( core_plugins += libnm_device_plugin_bluetooth -run_target( +test( 'check-local-devices-bluetooth', - command: [check_exports, libnm_device_plugin_bluetooth.full_path(), linker_script_devices], - depends: libnm_device_plugin_bluetooth + check_exports, + args: [libnm_device_plugin_bluetooth.full_path(), linker_script_devices], ) # FIXME: check_so_symbols replacement diff --git a/src/devices/bluetooth/nm-bluez-device.c b/src/devices/bluetooth/nm-bluez-device.c index d8e40d6f..b722f692 100644 --- a/src/devices/bluetooth/nm-bluez-device.c +++ b/src/devices/bluetooth/nm-bluez-device.c @@ -94,7 +94,7 @@ typedef struct { NMSettings *settings; GSList *connections; - NMConnection *pan_connection; + NMSettingsConnection *pan_connection; gboolean pan_connection_no_autocreate; } NMBluezDevicePrivate; @@ -114,8 +114,9 @@ G_DEFINE_TYPE (NMBluezDevice, nm_bluez_device, G_TYPE_OBJECT) /*****************************************************************************/ static void cp_connection_added (NMSettings *settings, - NMConnection *connection, NMBluezDevice *self); -static gboolean connection_compatible (NMBluezDevice *self, NMConnection *connection); + NMSettingsConnection *sett_conn, + NMBluezDevice *self); +static gboolean connection_compatible (NMBluezDevice *self, NMSettingsConnection *sett_conn); /*****************************************************************************/ @@ -181,10 +182,10 @@ nm_bluez_device_get_connected (NMBluezDevice *self) static void pan_connection_check_create (NMBluezDevice *self) { - NMConnection *connection; - NMConnection *added; + gs_unref_object NMConnection *connection = NULL; + NMSettingsConnection *added; NMSetting *setting; - char *id; + gs_free char *id = NULL; char uuid[37]; GError *error = NULL; NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); @@ -226,35 +227,25 @@ pan_connection_check_create (NMBluezDevice *self) NULL); nm_connection_add_setting (connection, setting); - /* Setting: IPv4 */ - setting = nm_setting_ip4_config_new (); - g_object_set (G_OBJECT (setting), - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, - NM_SETTING_IP_CONFIG_MAY_FAIL, FALSE, - NULL); - nm_connection_add_setting (connection, setting); - - /* Setting: IPv6 */ - setting = nm_setting_ip6_config_new (); - g_object_set (G_OBJECT (setting), - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE, - NULL); - nm_connection_add_setting (connection, setting); + if (!nm_connection_normalize (connection, NULL, NULL, &error)) { + nm_log_err (LOGD_BT, "bluez[%s] couldn't generate a connection for NAP device: %s", + priv->path, error->message); + g_error_free (error); + g_return_if_reached (); + } /* Adding a new connection raises a signal which eventually calls check_emit_usable (again) * which then already finds the suitable connection in priv->connections. This is confusing, * so block the signal. check_emit_usable will succeed after this function call returns. */ g_signal_handlers_block_by_func (priv->settings, cp_connection_added, self); - added = NM_CONNECTION (nm_settings_add_connection (priv->settings, connection, FALSE, &error)); + added = nm_settings_add_connection (priv->settings, connection, FALSE, &error); g_signal_handlers_unblock_by_func (priv->settings, cp_connection_added, self); if (added) { - g_assert (!g_slist_find (priv->connections, added)); - g_assert (connection_compatible (self, added)); - g_assert (nm_connection_compare (added, connection, NM_SETTING_COMPARE_FLAG_EXACT)); + nm_assert (!g_slist_find (priv->connections, added)); + nm_assert (connection_compatible (self, added)); - nm_settings_connection_set_flags (NM_SETTINGS_CONNECTION (added), NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, TRUE); + nm_settings_connection_set_flags (added, NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED, TRUE); priv->connections = g_slist_prepend (priv->connections, g_object_ref (added)); priv->pan_connection = added; @@ -263,11 +254,7 @@ pan_connection_check_create (NMBluezDevice *self) nm_log_warn (LOGD_BT, "bluez[%s] couldn't add new Bluetooth connection for NAP device: '%s' (%s): %s", priv->path, id, uuid, error->message); g_clear_error (&error); - } - g_object_unref (connection); - - g_free (id); } static gboolean @@ -321,9 +308,10 @@ check_emit_usable_schedule (NMBluezDevice *self) /*****************************************************************************/ static gboolean -connection_compatible (NMBluezDevice *self, NMConnection *connection) +connection_compatible (NMBluezDevice *self, NMSettingsConnection *sett_conn) { NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); + NMConnection *connection = nm_settings_connection_get_connection (sett_conn); NMSettingBluetooth *s_bt; const char *bt_type; const char *bdaddr; @@ -361,22 +349,24 @@ connection_compatible (NMBluezDevice *self, NMConnection *connection) } static gboolean -_internal_track_connection (NMBluezDevice *self, NMConnection *connection, gboolean tracked) +_internal_track_connection (NMBluezDevice *self, + NMSettingsConnection *sett_conn, + gboolean tracked) { NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); gboolean was_tracked; - was_tracked = !!g_slist_find (priv->connections, connection); + was_tracked = !!g_slist_find (priv->connections, sett_conn); if (was_tracked == !!tracked) return FALSE; if (tracked) - priv->connections = g_slist_prepend (priv->connections, g_object_ref (connection)); + priv->connections = g_slist_prepend (priv->connections, g_object_ref (sett_conn)); else { - priv->connections = g_slist_remove (priv->connections, connection); - if (priv->pan_connection == connection) + priv->connections = g_slist_remove (priv->connections, sett_conn); + if (priv->pan_connection == sett_conn) priv->pan_connection = NULL; - g_object_unref (connection); + g_object_unref (sett_conn); } return TRUE; @@ -384,32 +374,32 @@ _internal_track_connection (NMBluezDevice *self, NMConnection *connection, gbool static void cp_connection_added (NMSettings *settings, - NMConnection *connection, + NMSettingsConnection *sett_conn, NMBluezDevice *self) { - if (connection_compatible (self, connection)) { - if (_internal_track_connection (self, connection, TRUE)) + if (connection_compatible (self, sett_conn)) { + if (_internal_track_connection (self, sett_conn, TRUE)) check_emit_usable (self); } } static void cp_connection_removed (NMSettings *settings, - NMConnection *connection, + NMSettingsConnection *sett_conn, NMBluezDevice *self) { - if (_internal_track_connection (self, connection, FALSE)) + if (_internal_track_connection (self, sett_conn, FALSE)) check_emit_usable (self); } static void cp_connection_updated (NMSettings *settings, - NMConnection *connection, + NMSettingsConnection *sett_conn, gboolean by_user, NMBluezDevice *self) { - if (_internal_track_connection (self, connection, - connection_compatible (self, connection))) + if (_internal_track_connection (self, sett_conn, + connection_compatible (self, sett_conn))) check_emit_usable_schedule (self); } @@ -423,10 +413,8 @@ load_connections (NMBluezDevice *self) connections = nm_settings_get_connections (priv->settings, NULL); for (i = 0; connections[i]; i++) { - NMConnection *connection = (NMConnection *) connections[i]; - - if (connection_compatible (self, connection)) - changed |= _internal_track_connection (self, connection, TRUE); + if (connection_compatible (self, connections[i])) + changed |= _internal_track_connection (self, connections[i], TRUE); } if (changed) check_emit_usable (self); @@ -1178,14 +1166,14 @@ dispose (GObject *object) { NMBluezDevice *self = NM_BLUEZ_DEVICE (object); NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); - NMConnection *to_delete = NULL; + NMSettingsConnection *to_delete = NULL; nm_clear_g_source (&priv->check_emit_usable_id); if (priv->pan_connection) { /* Check whether we want to remove the created connection. If so, we take a reference * and delete it at the end of dispose(). */ - if (NM_FLAGS_HAS (nm_settings_connection_get_flags (NM_SETTINGS_CONNECTION (priv->pan_connection)), + if (NM_FLAGS_HAS (nm_settings_connection_get_flags (priv->pan_connection), NM_SETTINGS_CONNECTION_INT_FLAGS_NM_GENERATED)) to_delete = g_object_ref (priv->pan_connection); @@ -1219,8 +1207,8 @@ dispose (GObject *object) if (to_delete) { nm_log_dbg (LOGD_BT, "bluez[%s] removing Bluetooth connection for NAP device: '%s' (%s)", priv->path, - nm_connection_get_id (to_delete), nm_connection_get_uuid (to_delete)); - nm_settings_connection_delete (NM_SETTINGS_CONNECTION (to_delete), NULL); + nm_settings_connection_get_id (to_delete), nm_settings_connection_get_uuid (to_delete)); + nm_settings_connection_delete (to_delete, NULL); g_object_unref (to_delete); } diff --git a/src/devices/bluetooth/nm-bluez-manager.c b/src/devices/bluetooth/nm-bluez-manager.c index c74ecd81..711f2e57 100644 --- a/src/devices/bluetooth/nm-bluez-manager.c +++ b/src/devices/bluetooth/nm-bluez-manager.c @@ -244,8 +244,8 @@ setup_bluez5 (NMBluezManager *self) static void watch_name_on_appeared (GDBusConnection *connection, - const gchar *name, - const gchar *name_owner, + const char *name, + const char *name_owner, gpointer user_data) { check_bluez_and_try_setup (NM_BLUEZ_MANAGER (user_data)); diff --git a/src/devices/bluetooth/nm-bluez5-manager.c b/src/devices/bluetooth/nm-bluez5-manager.c index 5d3bd23a..e984212b 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.c +++ b/src/devices/bluetooth/nm-bluez5-manager.c @@ -224,7 +224,7 @@ network_server_unregister_bridge (const NMBtVTableNetworkServer *vtable, } static void -network_server_removed (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *self) +network_server_removed (GDBusProxy *proxy, const char *path, NMBluez5Manager *self) { NetworkServer *network_server; @@ -241,7 +241,7 @@ network_server_removed (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *s } static void -network_server_added (GDBusProxy *proxy, const gchar *path, const char *addr, NMBluez5Manager *self) +network_server_added (GDBusProxy *proxy, const char *path, const char *addr, NMBluez5Manager *self) { NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NetworkServer *network_server; @@ -342,7 +342,7 @@ device_initialized (NMBluezDevice *device, gboolean success, NMBluez5Manager *se } static void -device_added (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *self) +device_added (GDBusProxy *proxy, const char *path, NMBluez5Manager *self) { NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NMBluezDevice *device; @@ -356,7 +356,7 @@ device_added (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *self) } static void -device_removed (GDBusProxy *proxy, const gchar *path, NMBluez5Manager *self) +device_removed (GDBusProxy *proxy, const char *path, NMBluez5Manager *self) { NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); NMBluezDevice *device; diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 92ad0b31..1f650d33 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -36,6 +36,7 @@ #include "nm-setting-serial.h" #include "nm-setting-ppp.h" #include "NetworkManagerUtils.h" +#include "settings/nm-settings-connection.h" #include "nm-utils.h" #include "nm-bt-error.h" #include "platform/nm-platform.h" @@ -137,7 +138,7 @@ get_generic_capabilities (NMDevice *device) static gboolean can_auto_connect (NMDevice *device, - NMConnection *connection, + NMSettingsConnection *sett_conn, char **specific_object) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) device); @@ -145,11 +146,11 @@ can_auto_connect (NMDevice *device, nm_assert (!specific_object || !*specific_object); - if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->can_auto_connect (device, connection, NULL)) + if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->can_auto_connect (device, sett_conn, NULL)) return FALSE; /* Can't auto-activate a DUN connection without ModemManager */ - bt_type = get_connection_bt_type (connection); + bt_type = get_connection_bt_type (nm_settings_connection_get_connection (sett_conn)); if (bt_type == NM_BT_CAPABILITY_DUN && priv->mm_running == FALSE) return FALSE; @@ -157,36 +158,36 @@ can_auto_connect (NMDevice *device, } static gboolean -check_connection_compatible (NMDevice *device, NMConnection *connection) +check_connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) device); - NMSettingConnection *s_con; NMSettingBluetooth *s_bt; const char *bdaddr; guint32 bt_type; - if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->check_connection_compatible (device, connection)) + if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->check_connection_compatible (device, connection, error)) return FALSE; - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - - if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_BLUETOOTH_SETTING_NAME)) + bt_type = get_connection_bt_type (connection); + if (!NM_FLAGS_ALL (priv->capabilities, bt_type)) { + nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "device does not support bluetooth type of profile"); return FALSE; + } s_bt = nm_connection_get_setting_bluetooth (connection); - if (!s_bt) - return FALSE; - - bt_type = get_connection_bt_type (connection); - if (!(bt_type & priv->capabilities)) - return FALSE; bdaddr = nm_setting_bluetooth_get_bdaddr (s_bt); - if (!bdaddr) + if (!bdaddr) { + nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "profile lacks bdaddr setting"); return FALSE; - if (!nm_utils_hwaddr_matches (priv->bdaddr, -1, bdaddr, -1)) + } + if (!nm_utils_hwaddr_matches (priv->bdaddr, -1, bdaddr, -1)) { + nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "devices bdaddr setting mismatches"); return FALSE; + } return TRUE; } @@ -195,18 +196,25 @@ static gboolean check_connection_available (NMDevice *device, NMConnection *connection, NMDeviceCheckConAvailableFlags flags, - const char *specific_object) + const char *specific_object, + GError **error) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) device); guint32 bt_type; bt_type = get_connection_bt_type (connection); - if (!(bt_type & priv->capabilities)) + if (!(bt_type & priv->capabilities)) { + nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "device does not support bluetooth type"); return FALSE; + } /* DUN connections aren't available without ModemManager */ - if (bt_type == NM_BT_CAPABILITY_DUN && priv->mm_running == FALSE) + if (bt_type == NM_BT_CAPABILITY_DUN && priv->mm_running == FALSE) { + nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "ModemManager missing for DUN profile"); return FALSE; + } return TRUE; } @@ -1177,6 +1185,8 @@ nm_device_bt_class_init (NMDeviceBtClass *klass) dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_device_bluetooth); + device_class->connection_type_check_compatible = NM_SETTING_BLUETOOTH_SETTING_NAME; + device_class->get_generic_capabilities = get_generic_capabilities; device_class->can_auto_connect = can_auto_connect; device_class->deactivate = deactivate; |