*
* Connection Manager
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
gpointer key, val;
g_hash_table_iter_init(&iter, bluetooth_networks);
- while (g_hash_table_iter_next(&iter, &key, &val) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &val)) {
struct connman_network *known = val;
if (network != known)
static void connect_reply(DBusPendingCall *call, void *user_data)
{
- struct connman_network *network = user_data;
+ char *path = user_data;
+ struct connman_network *network;
DBusMessage *reply;
DBusError error;
const char *interface = NULL;
int index;
+ network = g_hash_table_lookup(bluetooth_networks, path);
+ if (!network)
+ return;
+
DBG("network %p", network);
reply = dbus_pending_call_steal_reply(call);
dbus_error_init(&error);
- if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ if (dbus_set_error_from_message(&error, reply)) {
connman_error("%s", error.message);
dbus_error_free(&error);
goto err;
}
- if (dbus_message_get_args(reply, &error,
- DBUS_TYPE_STRING, &interface,
- DBUS_TYPE_INVALID) == FALSE) {
- if (dbus_error_is_set(&error) == TRUE) {
+ if (!dbus_message_get_args(reply, &error, DBUS_TYPE_STRING,
+ &interface, DBUS_TYPE_INVALID)) {
+ if (dbus_error_is_set(&error)) {
connman_error("%s", error.message);
dbus_error_free(&error);
} else
goto err;
}
- if (interface == NULL)
+ if (!interface)
goto err;
DBG("interface %s", interface);
connman_network_set_index(network, index);
- connman_network_set_connected(network, TRUE);
+ connman_network_set_connected(network, true);
dbus_message_unref(reply);
return;
err:
- connman_network_set_connected(network, FALSE);
+ connman_network_set_connected(network, false);
dbus_message_unref(reply);
DBG("network %p", network);
- if (path == NULL)
+ if (!path)
return -EINVAL;
message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
BLUEZ_NETWORK_INTERFACE, CONNECT);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_set_auto_start(message, FALSE);
dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, message,
- &call, TIMEOUT * 10) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT * 10)) {
connman_error("Failed to connect service");
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
}
- dbus_pending_call_set_notify(call, connect_reply, network, NULL);
+ dbus_pending_call_set_notify(call, connect_reply, g_strdup(path),
+ g_free);
dbus_message_unref(message);
static void disconnect_reply(DBusPendingCall *call, void *user_data)
{
- struct connman_network *network = user_data;
+ char *path = user_data;
+ struct connman_network *network;
DBusMessage *reply;
DBusError error;
+ network = g_hash_table_lookup(bluetooth_networks, path);
+ if (!network)
+ return;
+
DBG("network %p", network);
reply = dbus_pending_call_steal_reply(call);
dbus_error_init(&error);
- if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ if (dbus_set_error_from_message(&error, reply)) {
connman_error("%s", error.message);
dbus_error_free(&error);
goto done;
}
- if (dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) == FALSE) {
- if (dbus_error_is_set(&error) == TRUE) {
+ if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID)) {
+ if (dbus_error_is_set(&error)) {
connman_error("%s", error.message);
dbus_error_free(&error);
} else
goto done;
}
- connman_network_set_connected(network, FALSE);
+ connman_network_set_connected(network, false);
done:
dbus_message_unref(reply);
DBG("network %p", network);
- if (path == NULL)
+ if (!path)
return -EINVAL;
message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
BLUEZ_NETWORK_INTERFACE, DISCONNECT);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_set_auto_start(message, FALSE);
dbus_message_append_args(message, DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, message,
- &call, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT)) {
connman_error("Failed to disconnect service");
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
connman_network_ref(network);
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
- dbus_pending_call_set_notify(call, disconnect_reply, network, NULL);
+ dbus_pending_call_set_notify(call, disconnect_reply, g_strdup(path),
+ g_free);
dbus_message_unref(message);
DBG("path %s", path);
network = g_hash_table_lookup(bluetooth_networks, path);
- if (network == NULL)
+ if (!network)
return TRUE;
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &key);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
- if (g_str_equal(key, "Connected") == TRUE) {
+ if (g_str_equal(key, "Connected")) {
dbus_bool_t connected;
dbus_message_iter_get_basic(&value, &connected);
- if (connected == TRUE)
+ if (connected)
return TRUE;
- connman_network_set_associating(network, FALSE);
- connman_network_set_connected(network, FALSE);
+ connman_network_set_associating(network, false);
+ connman_network_set_connected(network, false);
}
return TRUE;
{
DBusMessageIter array, dict;
- if (dbus_message_iter_init(reply, &array) == FALSE)
+ if (!dbus_message_iter_init(reply, &array))
return;
if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Adapter") == TRUE) {
- if (parent != NULL)
+ if (g_str_equal(key, "Adapter")) {
+ if (parent)
dbus_message_iter_get_basic(&value, parent);
- } else if (g_str_equal(key, "Address") == TRUE) {
- if (address != NULL)
+ } else if (g_str_equal(key, "Address")) {
+ if (address)
dbus_message_iter_get_basic(&value, address);
- } else if (g_str_equal(key, "Name") == TRUE) {
- if (name != NULL)
+ } else if (g_str_equal(key, "Name")) {
+ if (name)
dbus_message_iter_get_basic(&value, name);
- } else if (g_str_equal(key, "Alias") == TRUE) {
- if (alias != NULL)
+ } else if (g_str_equal(key, "Alias")) {
+ if (alias)
dbus_message_iter_get_basic(&value, alias);
- } else if (g_str_equal(key, "Powered") == TRUE) {
- if (powered != NULL)
+ } else if (g_str_equal(key, "Powered")) {
+ if (powered)
dbus_message_iter_get_basic(&value, powered);
- } else if (g_str_equal(key, "Discovering") == TRUE) {
- if (scanning != NULL)
+ } else if (g_str_equal(key, "Discovering")) {
+ if (scanning)
dbus_message_iter_get_basic(&value, scanning);
- } else if (g_str_equal(key, "Devices") == TRUE) {
- if (networks != NULL)
+ } else if (g_str_equal(key, "Devices")) {
+ if (networks)
memcpy(networks, &value, sizeof(value));
- } else if (g_str_equal(key, "UUIDs") == TRUE) {
- if (uuids != NULL)
+ } else if (g_str_equal(key, "UUIDs")) {
+ if (uuids)
memcpy(uuids, &value, sizeof(value));
}
extract_properties(reply, &parent, &address, NULL, &name,
NULL, NULL, &uuids, NULL);
- if (parent == NULL)
+ if (!parent)
goto done;
device = g_hash_table_lookup(bluetooth_devices, parent);
- if (device == NULL)
+ if (!device)
goto done;
- if (address == NULL)
+ if (!address)
goto done;
ether_aton_r(address, &addr);
addr.ether_addr_octet[4],
addr.ether_addr_octet[5]);
- if (has_pan(&uuids) == FALSE)
+ if (!has_pan(&uuids))
goto done;
network = connman_device_get_network(device, ident);
- if (network != NULL)
+ if (network)
goto done;
network = connman_network_create(ident,
CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN);
- if (network == NULL)
+ if (!network)
goto done;
connman_network_set_string(network, "Path", path);
message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
BLUEZ_DEVICE_INTERFACE, GET_PROPERTIES);
- if (message == NULL)
+ if (!message)
return;
dbus_message_set_auto_start(message, FALSE);
- if (dbus_connection_send_with_reply(connection, message,
- &call, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT)) {
connman_error("Failed to get network properties for %s", path);
goto done;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
goto done;
}
GSList *networks, *list;
networks = g_hash_table_lookup(pending_networks, adapter);
- if (networks == NULL)
+ if (!networks)
return;
- for (list = networks; list != NULL; list = list->next) {
+ for (list = networks; list; list = list->next) {
char *path = list->data;
add_network(path);
DBG("path %s", path);
device = g_hash_table_lookup(bluetooth_devices, path);
- if (device == NULL)
+ if (!device)
return TRUE;
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &key);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
- if (g_str_equal(key, "Powered") == TRUE) {
+ if (g_str_equal(key, "Powered")) {
dbus_bool_t val;
dbus_message_iter_get_basic(&value, &val);
connman_device_set_powered(device, val);
- if (val == TRUE)
+ if (val)
check_pending_networks(path);
- } else if (g_str_equal(key, "Discovering") == TRUE) {
+ } else if (g_str_equal(key, "Discovering")) {
dbus_bool_t val;
dbus_message_iter_get_basic(&value, &val);
- connman_device_set_scanning(device, val);
- } else if (g_str_equal(key, "Devices") == TRUE) {
+ connman_device_set_scanning(device,
+ CONNMAN_SERVICE_TYPE_BLUETOOTH, val);
+ } else if (g_str_equal(key, "Devices")) {
check_networks(&value);
}
DBG("");
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &network_path);
network = g_hash_table_lookup(bluetooth_networks, network_path);
- if (network == NULL)
+ if (!network)
return TRUE;
device = connman_network_get_device(network);
- if (device == NULL)
+ if (!device)
return TRUE;
g_hash_table_remove(bluetooth_networks, network_path);
DBG("path %s", path);
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &key);
DBG("key %s", key);
- if (g_str_equal(key, "UUIDs") == TRUE)
+ if (g_str_equal(key, "UUIDs"))
add_network(path);
return TRUE;
GSList *key_list = NULL;
GSList *list;
- if (bluetooth_networks == NULL)
+ if (!bluetooth_networks)
return;
g_hash_table_iter_init(&iter, bluetooth_networks);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
struct connman_network *network = value;
if (connman_network_get_device(network) != device)
key_list = g_slist_prepend(key_list, key);
}
- for (list = key_list; list != NULL; list = list->next) {
+ for (list = key_list; list; list = list->next) {
const char *network_path = list->data;
g_hash_table_remove(bluetooth_networks, network_path);
dbus_message_iter_next(&value);
}
- if (list == NULL)
+ if (!list)
return;
g_hash_table_replace(pending_networks, g_strdup(adapter), list);
reply = dbus_pending_call_steal_reply(call);
- if (path == NULL)
+ if (!path)
goto done;
extract_properties(reply, NULL, &address, &name, NULL,
&powered, &scanning, NULL, &networks);
- if (address == NULL)
+ if (!address)
goto done;
if (g_strcmp0(address, "00:00:00:00:00:00") == 0)
goto done;
device = g_hash_table_lookup(bluetooth_devices, path);
- if (device != NULL)
+ if (device)
goto update;
ether_aton_r(address, &addr);
device = connman_device_create("bluetooth_legacy",
CONNMAN_DEVICE_TYPE_BLUETOOTH);
- if (device == NULL)
+ if (!device)
goto done;
g_hash_table_insert(bluetooth_devices, g_strdup(path), device);
connman_device_set_string(device, "Path", path);
connman_device_set_powered(device, powered);
- connman_device_set_scanning(device, scanning);
+ connman_device_set_scanning(device,
+ CONNMAN_SERVICE_TYPE_BLUETOOTH, scanning);
- if (powered == FALSE) {
+ if (!powered) {
remove_device_networks(device);
add_pending_networks(path, &networks);
} else
message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
BLUEZ_ADAPTER_INTERFACE, GET_PROPERTIES);
- if (message == NULL)
+ if (!message)
return;
dbus_message_set_auto_start(message, FALSE);
- if (dbus_connection_send_with_reply(conn, message,
- &call, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(conn, message, &call, TIMEOUT)) {
connman_error("Failed to get adapter properties for %s", path);
goto done;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
goto done;
}
dbus_error_init(&error);
- if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ if (dbus_set_error_from_message(&error, reply)) {
connman_error("%s", error.message);
dbus_error_free(&error);
goto done;
}
- if (dbus_message_get_args(reply, &error,
- DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH,
- &adapters, &num_adapters,
- DBUS_TYPE_INVALID) == FALSE) {
- if (dbus_error_is_set(&error) == TRUE) {
+ if (!dbus_message_get_args(reply, &error, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_OBJECT_PATH, &adapters,
+ &num_adapters, DBUS_TYPE_INVALID)) {
+ if (dbus_error_is_set(&error)) {
connman_error("%s", error.message);
dbus_error_free(&error);
} else
DBG("network %p", network);
device = connman_network_get_device(network);
- if (device != NULL)
+ if (device)
connman_device_remove_network(device, network);
connman_network_unref(network);
message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
BLUEZ_MANAGER_INTERFACE, LIST_ADAPTERS);
- if (message == NULL)
+ if (!message)
return;
dbus_message_set_auto_start(message, FALSE);
- if (dbus_connection_send_with_reply(conn, message,
- &call, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(conn, message, &call, TIMEOUT)) {
connman_error("Failed to get Bluetooth adapters");
goto done;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
goto done;
}
{
DBG("connection %p", conn);
- if (bluetooth_devices == NULL)
+ if (!bluetooth_devices)
return;
g_hash_table_destroy(bluetooth_networks);
DBG("device %p", device);
- if (bluetooth_devices == NULL)
+ if (!bluetooth_devices)
return -ENOTSUP;
g_hash_table_iter_init(&iter, bluetooth_devices);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
struct connman_device *device_pan = value;
if (device == device_pan)
dbus_error_init(&error);
- if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ if (dbus_set_error_from_message(&error, reply)) {
connman_error("%s", error.message);
dbus_error_free(&error);
dbus_message_unref(reply);
DBG("");
- if (path == NULL)
+ if (!path)
return -EINVAL;
message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_set_auto_start(message, FALSE);
connman_dbus_property_append_basic(&iter, "Powered",
DBUS_TYPE_BOOLEAN, &powered);
- if (dbus_connection_send_with_reply(conn, message,
- &call, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(conn, message, &call, TIMEOUT)) {
connman_error("Failed to change Powered property");
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
dbus_error_init(&error);
- if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ if (dbus_set_error_from_message(&error, reply)) {
connman_error("%s", error.message);
dbus_error_free(&error);
dbus_message_unref(reply);
dbus_message_unref(reply);
dbus_pending_call_unref(call);
- connman_technology_tethering_notify(technology, TRUE);
+ connman_technology_tethering_notify(technology, true);
}
static void server_unregister_reply(DBusPendingCall *call, void *user_data)
dbus_error_init(&error);
- if (dbus_set_error_from_message(&error, reply) == TRUE) {
+ if (dbus_set_error_from_message(&error, reply)) {
connman_error("%s", error.message);
dbus_error_free(&error);
dbus_message_unref(reply);
dbus_message_unref(reply);
dbus_pending_call_unref(call);
- connman_technology_tethering_notify(technology, FALSE);
+ connman_technology_tethering_notify(technology, false);
}
static void server_register(const char *path, const char *uuid,
struct connman_technology *technology,
- const char *bridge, connman_bool_t enabled)
+ const char *bridge, bool enabled)
{
DBusMessage *message;
DBusPendingCall *call;
message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
BLUEZ_NETWORK_SERVER, command);
- if (message == NULL)
+ if (!message)
return;
dbus_message_set_auto_start(message, FALSE);
dbus_message_append_args(message, DBUS_TYPE_STRING, &uuid,
DBUS_TYPE_INVALID);
- if (enabled == TRUE)
+ if (enabled)
dbus_message_append_args(message, DBUS_TYPE_STRING, &bridge,
DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, message,
- &call, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &call, TIMEOUT)) {
connman_error("Failed to enable PAN server");
dbus_message_unref(message);
return;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return;
}
- if (enabled == TRUE)
+ if (enabled)
dbus_pending_call_set_notify(call, server_register_reply,
technology, NULL);
else
path = connman_device_get_string(device, "Path");
- server_register(path, "nap", info->technology, info->bridge, TRUE);
+ server_register(path, "nap", info->technology, info->bridge, true);
}
static void disable_nap(gpointer key, gpointer value, gpointer user_data)
path = connman_device_get_string(device, "Path");
- server_register(path, "nap", info->technology, info->bridge, FALSE);
+ server_register(path, "nap", info->technology, info->bridge, false);
}
static int tech_set_tethering(struct connman_technology *technology,
const char *identifier, const char *passphrase,
- const char *bridge, connman_bool_t enabled)
+ const char *bridge, bool enabled)
{
struct tethering_info info = {
.technology = technology,
DBG("bridge %s", bridge);
+ if (!bluetooth_devices)
+ return -ENOTCONN;
+
if (enabled)
g_hash_table_foreach(bluetooth_devices, enable_nap, &info);
else
int err;
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
g_dbus_remove_watch(connection, device_watch);
g_dbus_remove_watch(connection, network_watch);
+ /*
+ * We unset the disabling of the Bluetooth device when shutting down
+ * so that non-PAN BT connections are not affected.
+ */
+ bluetooth_driver.disable = NULL;
+
bluetooth_disconnect(connection, NULL);
connman_technology_driver_unregister(&tech_driver);