diff options
Diffstat (limited to 'src/core/devices/bluetooth')
| -rw-r--r-- | src/core/devices/bluetooth/nm-bluez-manager.c | 163 | ||||
| -rw-r--r-- | src/core/devices/bluetooth/nm-bluez5-dun.c | 44 | ||||
| -rw-r--r-- | src/core/devices/bluetooth/nm-device-bt.c | 31 | ||||
| -rw-r--r-- | src/core/devices/bluetooth/tests/nm-bt-test.c | 2 |
4 files changed, 102 insertions, 138 deletions
diff --git a/src/core/devices/bluetooth/nm-bluez-manager.c b/src/core/devices/bluetooth/nm-bluez-manager.c index fc081580..36e442ad 100644 --- a/src/core/devices/bluetooth/nm-bluez-manager.c +++ b/src/core/devices/bluetooth/nm-bluez-manager.c @@ -31,9 +31,9 @@ /*****************************************************************************/ #if WITH_BLUEZ5_DUN - #define _NM_BT_CAPABILITY_SUPPORTED_DUN NM_BT_CAPABILITY_DUN +#define _NM_BT_CAPABILITY_SUPPORTED_DUN NM_BT_CAPABILITY_DUN #else - #define _NM_BT_CAPABILITY_SUPPORTED_DUN NM_BT_CAPABILITY_NONE +#define _NM_BT_CAPABILITY_SUPPORTED_DUN NM_BT_CAPABILITY_NONE #endif #define _NM_BT_CAPABILITY_SUPPORTED (NM_BT_CAPABILITY_NAP | _NM_BT_CAPABILITY_SUPPORTED_DUN) @@ -382,64 +382,56 @@ _bzobj_to_string(const BzDBusObj *bzobj, char *buf, gsize len) buf[0] = '\0'; if (bzobj->d_has_adapter_iface) { - nm_utils_strbuf_append_str(&buf, &len, prefix); + nm_strbuf_append_str(&buf, &len, prefix); prefix = ", "; - nm_utils_strbuf_append_str(&buf, &len, "Adapter1 {"); + nm_strbuf_append_str(&buf, &len, "Adapter1 {"); if (bzobj->d_adapter.address) { - nm_utils_strbuf_append(&buf, &len, " d.address: \"%s\"", bzobj->d_adapter.address); + nm_strbuf_append(&buf, &len, " d.address: \"%s\"", bzobj->d_adapter.address); if (bzobj->d_adapter_powered) - nm_utils_strbuf_append_str(&buf, &len, ","); + nm_strbuf_append_str(&buf, &len, ","); } if (bzobj->d_adapter_powered) - nm_utils_strbuf_append(&buf, &len, " d.powered: 1"); - nm_utils_strbuf_append_str(&buf, &len, " }"); + nm_strbuf_append(&buf, &len, " d.powered: 1"); + nm_strbuf_append_str(&buf, &len, " }"); } if (bzobj->d_has_device_iface) { const char *prefix1 = ""; - nm_utils_strbuf_append_str(&buf, &len, prefix); + nm_strbuf_append_str(&buf, &len, prefix); prefix = ", "; - nm_utils_strbuf_append_str(&buf, &len, "Device1 {"); + nm_strbuf_append_str(&buf, &len, "Device1 {"); if (bzobj->d_device.address) { - nm_utils_strbuf_append(&buf, - &len, - "%s d.address: \"%s\"", - prefix1, - bzobj->d_device.address); + nm_strbuf_append(&buf, &len, "%s d.address: \"%s\"", prefix1, bzobj->d_device.address); prefix1 = ","; } if (bzobj->d_device.name) { - nm_utils_strbuf_append(&buf, &len, "%s d.name: \"%s\"", prefix1, bzobj->d_device.name); + nm_strbuf_append(&buf, &len, "%s d.name: \"%s\"", prefix1, bzobj->d_device.name); prefix1 = ","; } if (bzobj->d_device.adapter) { - nm_utils_strbuf_append(&buf, - &len, - "%s d.adapter: \"%s\"", - prefix1, - bzobj->d_device.adapter); + nm_strbuf_append(&buf, &len, "%s d.adapter: \"%s\"", prefix1, bzobj->d_device.adapter); prefix1 = ","; } if (bzobj->d_device_capabilities != NM_BT_CAPABILITY_NONE) { - nm_utils_strbuf_append(&buf, - &len, - "%s d.capabilities: \"%s\"", - prefix1, - nm_bluetooth_capability_to_string(bzobj->d_device_capabilities, - sbuf_cap, - sizeof(sbuf_cap))); + nm_strbuf_append(&buf, + &len, + "%s d.capabilities: \"%s\"", + prefix1, + nm_bluetooth_capability_to_string(bzobj->d_device_capabilities, + sbuf_cap, + sizeof(sbuf_cap))); prefix1 = ","; } if (bzobj->d_device_connected) { - nm_utils_strbuf_append(&buf, &len, "%s d.connected: 1", prefix1); + nm_strbuf_append(&buf, &len, "%s d.connected: 1", prefix1); prefix1 = ","; } if (bzobj->d_device_paired) { - nm_utils_strbuf_append(&buf, &len, "%s d.paired: 1", prefix1); + nm_strbuf_append(&buf, &len, "%s d.paired: 1", prefix1); prefix1 = ","; } - nm_utils_strbuf_append_str(&buf, &len, " }"); + nm_strbuf_append_str(&buf, &len, " }"); } network_server_is_usable = _bzobjs_network_server_is_usable(bzobj, TRUE); @@ -450,43 +442,43 @@ _bzobj_to_string(const BzDBusObj *bzobj, char *buf, gsize len) || !nm_streq0(bzobj->d_has_adapter_iface ? bzobj->d_adapter.address : NULL, bzobj->x_network_server.adapter_address) || bzobj->x_network_server.device_br || bzobj->x_network_server.r_req_data) { - nm_utils_strbuf_append_str(&buf, &len, prefix); + nm_strbuf_append_str(&buf, &len, prefix); prefix = ", "; - nm_utils_strbuf_append(&buf, &len, "NetworkServer1 { "); + nm_strbuf_append(&buf, &len, "NetworkServer1 { "); if (!bzobj->d_has_network_server_iface) - nm_utils_strbuf_append(&buf, &len, " has-d-iface: 0, "); + nm_strbuf_append(&buf, &len, " has-d-iface: 0, "); if (network_server_is_usable != (!c_list_is_empty(&bzobj->x_network_server.lst))) - nm_utils_strbuf_append(&buf, - &len, - "usable: %d, used: %d", - !!network_server_is_usable, - !network_server_is_usable); + nm_strbuf_append(&buf, + &len, + "usable: %d, used: %d", + !!network_server_is_usable, + !network_server_is_usable); else if (network_server_is_usable) - nm_utils_strbuf_append(&buf, &len, "used: 1"); + nm_strbuf_append(&buf, &len, "used: 1"); else - nm_utils_strbuf_append(&buf, &len, "usable: 0"); + nm_strbuf_append(&buf, &len, "usable: 0"); if (!nm_streq0(bzobj->d_has_adapter_iface ? bzobj->d_adapter.address : NULL, bzobj->x_network_server.adapter_address)) { if (bzobj->x_network_server.adapter_address) - nm_utils_strbuf_append(&buf, - &len, - ", adapter-address: \"%s\"", - bzobj->x_network_server.adapter_address); + nm_strbuf_append(&buf, + &len, + ", adapter-address: \"%s\"", + bzobj->x_network_server.adapter_address); else - nm_utils_strbuf_append(&buf, &len, ", adapter-address: <NULL>"); + nm_strbuf_append(&buf, &len, ", adapter-address: <NULL>"); } if (bzobj->x_network_server.device_br) - nm_utils_strbuf_append(&buf, &len, ", bridge-device: 1"); + nm_strbuf_append(&buf, &len, ", bridge-device: 1"); if (bzobj->x_network_server.r_req_data) - nm_utils_strbuf_append(&buf, &len, ", register-in-progress: 1"); + nm_strbuf_append(&buf, &len, ", register-in-progress: 1"); - nm_utils_strbuf_append_str(&buf, &len, " }"); + nm_strbuf_append_str(&buf, &len, " }"); } device_is_usable = _bzobjs_device_is_usable(bzobj, NULL, &create_panu_connection); @@ -497,76 +489,72 @@ _bzobj_to_string(const BzDBusObj *bzobj, char *buf, gsize len) || bzobj->x_device_connect_bt_type != NM_BT_CAPABILITY_NONE || bzobj->x_device.connect_dun_context || bzobj->x_device.c_req_data || bzobj->x_device_is_connected != bzobj->d_network_connected) { - nm_utils_strbuf_append_str(&buf, &len, prefix); + nm_strbuf_append_str(&buf, &len, prefix); prefix = ", "; - nm_utils_strbuf_append_str(&buf, &len, "Network1 {"); + nm_strbuf_append_str(&buf, &len, "Network1 {"); if (bzobj->d_network.interface) - nm_utils_strbuf_append(&buf, - &len, - " d.interface: \"%s\", ", - bzobj->d_network.interface); + nm_strbuf_append(&buf, &len, " d.interface: \"%s\", ", bzobj->d_network.interface); if (bzobj->d_network_connected) - nm_utils_strbuf_append(&buf, &len, " d.connected: %d, ", !!bzobj->d_network_connected); + nm_strbuf_append(&buf, &len, " d.connected: %d, ", !!bzobj->d_network_connected); if (!bzobj->d_has_network_iface) - nm_utils_strbuf_append(&buf, &len, " has-d-iface: 0, "); + nm_strbuf_append(&buf, &len, " has-d-iface: 0, "); if (device_is_usable != bzobj->x_device_is_usable) - nm_utils_strbuf_append(&buf, - &len, - " usable: %d, used: %d", - !!device_is_usable, - !device_is_usable); + nm_strbuf_append(&buf, + &len, + " usable: %d, used: %d", + !!device_is_usable, + !device_is_usable); else if (device_is_usable) - nm_utils_strbuf_append(&buf, &len, " used: 1"); + nm_strbuf_append(&buf, &len, " used: 1"); else - nm_utils_strbuf_append(&buf, &len, " usable: 0"); + nm_strbuf_append(&buf, &len, " usable: 0"); if (create_panu_connection) - nm_utils_strbuf_append(&buf, &len, ", create-panu-connection: 1"); + nm_strbuf_append(&buf, &len, ", create-panu-connection: 1"); if (bzobj->x_device.panu_connection) - nm_utils_strbuf_append(&buf, &len, ", has-panu-connection: 1"); + nm_strbuf_append(&buf, &len, ", has-panu-connection: 1"); if (bzobj->x_device.device_bt) - nm_utils_strbuf_append(&buf, &len, ", has-device: 1"); + nm_strbuf_append(&buf, &len, ", has-device: 1"); if (bzobj->x_device_connect_bt_type != NM_BT_CAPABILITY_NONE || bzobj->x_device.connect_dun_context) { - nm_utils_strbuf_append( - &buf, - &len, - ", connect: %s%s", - nm_bluetooth_capability_to_string(bzobj->x_device_connect_bt_type, - sbuf_cap, - sizeof(sbuf_cap)), - bzobj->x_device.connect_dun_context ? ",with-dun-context" : ""); + nm_strbuf_append(&buf, + &len, + ", connect: %s%s", + nm_bluetooth_capability_to_string(bzobj->x_device_connect_bt_type, + sbuf_cap, + sizeof(sbuf_cap)), + bzobj->x_device.connect_dun_context ? ",with-dun-context" : ""); } if (bzobj->x_device.c_req_data) - nm_utils_strbuf_append(&buf, &len, ", connecting: 1"); + nm_strbuf_append(&buf, &len, ", connecting: 1"); if (bzobj->x_device_is_connected != bzobj->d_network_connected) - nm_utils_strbuf_append(&buf, &len, ", connected: %d", !!bzobj->x_device_is_connected); + nm_strbuf_append(&buf, &len, ", connected: %d", !!bzobj->x_device_is_connected); - nm_utils_strbuf_append_str(&buf, &len, " }"); + nm_strbuf_append_str(&buf, &len, " }"); } if (_bzobjs_is_dead(bzobj)) { - nm_utils_strbuf_append_str(&buf, &len, prefix); + nm_strbuf_append_str(&buf, &len, prefix); prefix = ", "; - nm_utils_strbuf_append_str(&buf, &len, "dead: 1"); + nm_strbuf_append_str(&buf, &len, "dead: 1"); } if (!c_list_is_empty(&bzobj->process_change_lst)) { - nm_utils_strbuf_append_str(&buf, &len, prefix); + nm_strbuf_append_str(&buf, &len, prefix); prefix = ", "; - nm_utils_strbuf_append(&buf, &len, "change-pending-on-idle: 1"); + nm_strbuf_append(&buf, &len, "change-pending-on-idle: 1"); } if (_bzobjs_adapter_is_usable_for_device(bzobj) != bzobj->was_usable_adapter_for_device_before) { - nm_utils_strbuf_append_str(&buf, &len, prefix); + nm_strbuf_append_str(&buf, &len, prefix); prefix = ", "; - nm_utils_strbuf_append(&buf, &len, "change-usable-adapter-for-device: 1"); + nm_strbuf_append(&buf, &len, "change-usable-adapter-for-device: 1"); } return buf0; @@ -2864,9 +2852,7 @@ dispose(GObject *object) * BzDBusObj instances and do necessary cleanup actions (like disconnecting devices * or deleting panu_connection). */ - nm_assert(c_list_is_empty(&priv->network_server_lst_head)); - nm_assert(c_list_is_empty(&priv->process_change_lst_head)); - nm_assert(priv->process_change_idle_id == 0); + nm_clear_g_source(&priv->process_change_idle_id); g_atomic_pointer_compare_and_exchange(&nm_bt_vtable_network_server, &priv->vtable_network_server, @@ -2883,6 +2869,9 @@ dispose(GObject *object) nm_clear_pointer(&priv->bzobjs, g_hash_table_destroy); nm_clear_pointer(&priv->conn_data_heads, g_hash_table_destroy); nm_clear_pointer(&priv->conn_data_elems, g_hash_table_destroy); + + nm_assert(c_list_is_empty(&priv->network_server_lst_head)); + nm_assert(c_list_is_empty(&priv->process_change_lst_head)); } static void diff --git a/src/core/devices/bluetooth/nm-bluez5-dun.c b/src/core/devices/bluetooth/nm-bluez5-dun.c index e29884d8..7efbfaf4 100644 --- a/src/core/devices/bluetooth/nm-bluez5-dun.c +++ b/src/core/devices/bluetooth/nm-bluez5-dun.c @@ -182,25 +182,18 @@ _connect_open_tty(NMBluez5DunContext *context) nm_strerror_native(errsv), errsv); context->cdat->connect_open_tty_started_at = nm_utils_get_monotonic_timestamp_nsec(); - context->cdat->source = nm_g_timeout_source_new(100, - G_PRIORITY_DEFAULT, - _connect_open_tty_retry_cb, - context, - NULL); - g_source_attach(context->cdat->source, NULL); + context->cdat->source = + nm_g_timeout_add_source(100, _connect_open_tty_retry_cb, context); } return -errsv; } context->rfcomm_tty_fd = fd; - context->rfcomm_tty_poll_source = nm_g_unix_fd_source_new(context->rfcomm_tty_fd, + context->rfcomm_tty_poll_source = nm_g_unix_fd_add_source(context->rfcomm_tty_fd, G_IO_ERR | G_IO_HUP, - G_PRIORITY_DEFAULT, _rfcomm_tty_poll_cb, - context, - NULL); - g_source_attach(context->rfcomm_tty_poll_source, NULL); + context); _context_invoke_callback_success(context); return 0; @@ -369,13 +362,10 @@ _connect_socket_connect(NMBluez5DunContext *context) context->dst_str, context->rfcomm_channel); - context->cdat->source = nm_g_unix_fd_source_new(context->rfcomm_sock_fd, + context->cdat->source = nm_g_unix_fd_add_source(context->rfcomm_sock_fd, G_IO_OUT, - G_PRIORITY_DEFAULT, _connect_socket_connect_cb, - context, - NULL); - g_source_attach(context->cdat->source, NULL); + context); return; } @@ -567,12 +557,8 @@ _connect_sdp_io_cb(int fd, GIOCondition condition, gpointer user_data) nm_strerror_native(errsv), errsv); nm_clear_g_source_inst(&context->cdat->source); - context->cdat->source = nm_g_timeout_source_new(1000, - G_PRIORITY_DEFAULT, - _connect_sdp_session_start_on_idle_cb, - context, - NULL); - g_source_attach(context->cdat->source, NULL); + context->cdat->source = + nm_g_timeout_add_source(1000, _connect_sdp_session_start_on_idle_cb, context); return G_SOURCE_REMOVE; } @@ -616,13 +602,10 @@ _connect_sdp_io_cb(int fd, GIOCondition condition, gpointer user_data) } /* Set callback responsible for update the internal SDP transaction */ - context->cdat->source = nm_g_unix_fd_source_new(fd, + context->cdat->source = nm_g_unix_fd_add_source(fd, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - G_PRIORITY_DEFAULT, _connect_sdp_search_io_cb, - context, - NULL); - g_source_attach(context->cdat->source, NULL); + context); done: if (error) @@ -664,13 +647,10 @@ _connect_sdp_session_start(NMBluez5DunContext *context, GError **error) return FALSE; } - context->cdat->source = nm_g_unix_fd_source_new(sdp_get_socket(context->cdat->sdp_session), + context->cdat->source = nm_g_unix_fd_add_source(sdp_get_socket(context->cdat->sdp_session), G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - G_PRIORITY_DEFAULT, _connect_sdp_io_cb, - context, - NULL); - g_source_attach(context->cdat->source, NULL); + context); return TRUE; } diff --git a/src/core/devices/bluetooth/nm-device-bt.c b/src/core/devices/bluetooth/nm-device-bt.c index 8f4ceba7..3dbfbbe0 100644 --- a/src/core/devices/bluetooth/nm-device-bt.c +++ b/src/core/devices/bluetooth/nm-device-bt.c @@ -10,6 +10,7 @@ #include <stdio.h> #include <linux/if_ether.h> +#include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-bluez-common.h" #include "nm-bluez-manager.h" @@ -273,11 +274,7 @@ complete_connection(NMDevice * device, s_serial = nm_connection_get_setting_serial(connection); s_ppp = nm_connection_get_setting_ppp(connection); - s_bt = nm_connection_get_setting_bluetooth(connection); - if (!s_bt) { - s_bt = (NMSettingBluetooth *) nm_setting_bluetooth_new(); - nm_connection_add_setting(connection, NM_SETTING(s_bt)); - } + s_bt = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_BLUETOOTH); ctype = nm_setting_bluetooth_get_connection_type(s_bt); if (ctype) { @@ -1007,21 +1004,21 @@ act_stage3_ip_config_start(NMDevice * device, gpointer * out_config, NMDeviceStateReason *out_failure_reason) { - NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(device); + NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE(device); + gboolean autoip4 = FALSE; + NMActStageReturn ret; - nm_assert_addr_family(addr_family); + if (priv->connect_bt_type != NM_BT_CAPABILITY_DUN) + goto out_chain_up; - if (priv->connect_bt_type == NM_BT_CAPABILITY_DUN) { - if (addr_family == AF_INET) { - return nm_modem_stage3_ip4_config_start(priv->modem, - device, - NM_DEVICE_CLASS(nm_device_bt_parent_class), - out_failure_reason); - } else { - return nm_modem_stage3_ip6_config_start(priv->modem, device, out_failure_reason); - } - } + if (!NM_IS_IPv4(addr_family)) + return nm_modem_stage3_ip6_config_start(priv->modem, device, out_failure_reason); + + ret = nm_modem_stage3_ip4_config_start(priv->modem, device, &autoip4, out_failure_reason); + if (ret != NM_ACT_STAGE_RETURN_SUCCESS || !autoip4) + return ret; +out_chain_up: return NM_DEVICE_CLASS(nm_device_bt_parent_class) ->act_stage3_ip_config_start(device, addr_family, out_config, out_failure_reason); } diff --git a/src/core/devices/bluetooth/tests/nm-bt-test.c b/src/core/devices/bluetooth/tests/nm-bt-test.c index 0fc8aa87..548e7249 100644 --- a/src/core/devices/bluetooth/tests/nm-bt-test.c +++ b/src/core/devices/bluetooth/tests/nm-bt-test.c @@ -2,8 +2,6 @@ #include "src/core/nm-default-daemon.h" -#include <glib-unix.h> - #include "devices/bluetooth/nm-bluez5-dun.h" #include "nm-test-utils-core.h" |