summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 10:37:39 +0800
committerZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 10:37:39 +0800
commit1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7 (patch)
tree6e991827d28537f7f40f20786c2354fd04a9fdad /plugins
parentfbe905ab58ecc31fe64c410c5f580cadc30e7f04 (diff)
downloadconnman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.gz
connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.bz2
connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.zip
Imported Upstream version 1.24upstream/1.24
Diffstat (limited to 'plugins')
-rw-r--r--plugins/bluetooth.c296
-rw-r--r--plugins/bluetooth_legacy.c268
-rw-r--r--plugins/dundee.c104
-rw-r--r--plugins/ethernet.c230
-rw-r--r--plugins/gadget.c358
-rw-r--r--plugins/hh2serial-gps.c22
-rw-r--r--plugins/iospm.c11
-rw-r--r--plugins/loopback.c20
-rw-r--r--plugins/neard.c86
-rw-r--r--plugins/nmcompat.c30
-rw-r--r--plugins/ofono.c635
-rw-r--r--plugins/pacrunner.c63
-rw-r--r--plugins/session_policy_local.c118
-rw-r--r--plugins/tist.c26
-rw-r--r--plugins/vpn.c384
-rw-r--r--plugins/wifi.c802
16 files changed, 2031 insertions, 1422 deletions
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 4aac1e03..82217d03 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -44,7 +44,7 @@ static DBusConnection *connection;
static GDBusClient *client;
static GHashTable *devices;
static GHashTable *networks;
-static connman_bool_t bluetooth_tethering;
+static bool bluetooth_tethering;
struct bluetooth_pan {
struct connman_network *network;
@@ -68,32 +68,32 @@ static const char *proxy_get_string(GDBusProxy *proxy, const char *property)
DBusMessageIter iter;
const char *str;
- if (g_dbus_proxy_get_property(proxy, property, &iter) == FALSE)
+ if (!g_dbus_proxy_get_property(proxy, property, &iter))
return NULL;
dbus_message_iter_get_basic(&iter, &str);
return str;
}
-static connman_bool_t proxy_get_bool(GDBusProxy *proxy, const char *property)
+static bool proxy_get_bool(GDBusProxy *proxy, const char *property)
{
DBusMessageIter iter;
- connman_bool_t value;
+ dbus_bool_t value;
- if (g_dbus_proxy_get_property(proxy, property, &iter) == FALSE)
- return FALSE;
+ if (!g_dbus_proxy_get_property(proxy, property, &iter))
+ return false;
dbus_message_iter_get_basic(&iter, &value);
return value;
}
-static connman_bool_t proxy_get_nap(GDBusProxy *proxy)
+static bool proxy_get_nap(GDBusProxy *proxy)
{
DBusMessageIter iter, value;
- if (proxy == NULL)
- return FALSE;
+ if (!proxy)
+ return false;
- if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE)
- return FALSE;
+ if (!g_dbus_proxy_get_property(proxy, "UUIDs", &iter))
+ return false;
dbus_message_iter_recurse(&iter, &value);
while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
@@ -101,11 +101,12 @@ static connman_bool_t proxy_get_nap(GDBusProxy *proxy)
dbus_message_iter_get_basic(&value, &uuid);
if (strcmp(uuid, BLUETOOTH_PAN_NAP) == 0)
- return TRUE;
+ return true;
dbus_message_iter_next(&value);
}
- return FALSE;
+
+ return false;
}
static int bluetooth_pan_probe(struct connman_network *network)
@@ -117,7 +118,7 @@ static int bluetooth_pan_probe(struct connman_network *network)
g_hash_table_iter_init(&iter, networks);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
struct bluetooth_pan *pan = value;
if (network == pan->network)
@@ -134,14 +135,14 @@ static void pan_remove_nap(struct bluetooth_pan *pan)
DBG("network %p pan %p", pan->network, pan);
- if (network == NULL)
+ if (!network)
return;
pan->network = NULL;
connman_network_set_data(network, NULL);
device = connman_network_get_device(network);
- if (device != NULL)
+ if (device)
connman_device_remove_network(device, network);
connman_network_unref(network);
@@ -155,34 +156,34 @@ static void bluetooth_pan_remove(struct connman_network *network)
connman_network_set_data(network, NULL);
- if (pan != NULL)
+ if (pan)
pan_remove_nap(pan);
}
-static connman_bool_t pan_connect(struct bluetooth_pan *pan,
+static bool pan_connect(struct bluetooth_pan *pan,
const char *iface)
{
int index;
- if (iface == NULL) {
- if (proxy_get_bool(pan->btnetwork_proxy, "Connected") == FALSE)
- return FALSE;
+ if (!iface) {
+ if (!proxy_get_bool(pan->btnetwork_proxy, "Connected"))
+ return false;
iface = proxy_get_string(pan->btnetwork_proxy, "Interface");
}
- if (iface == NULL)
- return FALSE;
+ if (!iface)
+ return false;
index = connman_inet_ifindex(iface);
if (index < 0) {
DBG("network %p invalid index %d", pan->network, index);
- return FALSE;
+ return false;
}
connman_network_set_index(pan->network, index);
- connman_network_set_connected(pan->network, TRUE);
+ connman_network_set_connected(pan->network, true);
- return TRUE;
+ return true;
}
static void pan_connect_cb(DBusMessage *message, void *user_data)
@@ -193,7 +194,7 @@ static void pan_connect_cb(DBusMessage *message, void *user_data)
DBusMessageIter iter;
pan = g_hash_table_lookup(networks, path);
- if (pan == NULL) {
+ if (!pan) {
DBG("network already removed");
return;
}
@@ -210,7 +211,7 @@ static void pan_connect_cb(DBusMessage *message, void *user_data)
return;
}
} else {
- if (dbus_message_iter_init(message, &iter) == TRUE &&
+ if (dbus_message_iter_init(message, &iter) &&
dbus_message_iter_get_arg_type(&iter) ==
DBUS_TYPE_STRING)
dbus_message_iter_get_basic(&iter, &iface);
@@ -236,17 +237,17 @@ static int bluetooth_pan_connect(struct connman_network *network)
DBG("network %p", network);
- if (pan == NULL)
+ if (!pan)
return -EINVAL;
path = g_dbus_proxy_get_path(pan->btnetwork_proxy);
- if (g_dbus_proxy_method_call(pan->btnetwork_proxy, "Connect",
- pan_connect_append, pan_connect_cb,
- g_strdup(path), g_free) == FALSE)
+ if (!g_dbus_proxy_method_call(pan->btnetwork_proxy, "Connect",
+ pan_connect_append, pan_connect_cb,
+ g_strdup(path), g_free))
return -EIO;
- connman_network_set_associating(pan->network, TRUE);
+ connman_network_set_associating(pan->network, true);
return -EINPROGRESS;
}
@@ -257,7 +258,7 @@ static void pan_disconnect_cb(DBusMessage *message, void *user_data)
struct bluetooth_pan *pan;
pan = g_hash_table_lookup(networks, path);
- if (pan == NULL) {
+ if (!pan) {
DBG("network already removed");
return;
}
@@ -270,7 +271,7 @@ static void pan_disconnect_cb(DBusMessage *message, void *user_data)
DBG("network %p", pan->network);
- connman_network_set_connected(pan->network, FALSE);
+ connman_network_set_connected(pan->network, false);
}
static int bluetooth_pan_disconnect(struct connman_network *network)
@@ -280,14 +281,13 @@ static int bluetooth_pan_disconnect(struct connman_network *network)
DBG("network %p", network);
- if (pan == NULL)
+ if (!pan)
return -EINVAL;
path = g_dbus_proxy_get_path(pan->btnetwork_proxy);
- if (g_dbus_proxy_method_call(pan->btnetwork_proxy, "Disconnect",
- NULL, pan_disconnect_cb,
- g_strdup(path), g_free) == FALSE)
+ if (!g_dbus_proxy_method_call(pan->btnetwork_proxy, "Disconnect",
+ NULL, pan_disconnect_cb, g_strdup(path), g_free))
return -EIO;
return -EINPROGRESS;
@@ -297,20 +297,23 @@ static void btnetwork_property_change(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter, void *user_data)
{
struct bluetooth_pan *pan;
- connman_bool_t proxy_connected, network_connected;
+ dbus_bool_t connected;
+ bool proxy_connected, network_connected;
if (strcmp(name, "Connected") != 0)
return;
pan = g_hash_table_lookup(networks, g_dbus_proxy_get_path(proxy));
- if (pan == NULL || pan->network == NULL)
+ if (!pan || !pan->network)
return;
- dbus_message_iter_get_basic(iter, &proxy_connected);
+ dbus_message_iter_get_basic(iter, &connected);
+ proxy_connected = connected;
+
network_connected = connman_network_get_connected(pan->network);
- DBG("network %p network connected %d proxy connected %d",
- pan->network, network_connected, proxy_connected);
+ DBG("network %p network connected %d proxy connected %d",
+ pan->network, network_connected, proxy_connected);
if (network_connected != proxy_connected)
connman_network_set_connected(pan->network, proxy_connected);
@@ -320,7 +323,7 @@ static void pan_create_nap(struct bluetooth_pan *pan)
{
struct connman_device *device;
- if (proxy_get_nap(pan->btdevice_proxy) == FALSE) {
+ if (!proxy_get_nap(pan->btdevice_proxy)) {
pan_remove_nap(pan);
return;
}
@@ -328,15 +331,20 @@ static void pan_create_nap(struct bluetooth_pan *pan)
device = g_hash_table_lookup(devices,
proxy_get_string(pan->btdevice_proxy, "Adapter"));
- if (device == NULL || connman_device_get_powered(device) == FALSE)
+ if (!device || !connman_device_get_powered(device))
return;
- if (pan->network == NULL) {
+ if (!pan->network) {
const char *address;
char ident[BLUETOOTH_ADDR_LEN * 2 + 1];
const char *name, *path;
address = proxy_get_string(pan->btdevice_proxy, "Address");
+ if (!address) {
+ connman_warn("Bluetooth device address missing");
+ return;
+ }
+
address2ident(address, ident);
pan->network = connman_network_create(ident,
@@ -347,7 +355,7 @@ static void pan_create_nap(struct bluetooth_pan *pan)
DBG("network %p %s %s", pan->network, path, name);
- if (pan->network == NULL) {
+ if (!pan->network) {
connman_warn("Bluetooth network %s creation failed",
path);
return;
@@ -360,7 +368,7 @@ static void pan_create_nap(struct bluetooth_pan *pan)
connman_device_add_network(device, pan->network);
- if (pan_connect(pan, NULL) == TRUE)
+ if (pan_connect(pan, NULL))
DBG("network %p already connected", pan->network);
}
@@ -368,18 +376,18 @@ static void btdevice_property_change(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter, void *user_data)
{
struct bluetooth_pan *pan;
- connman_bool_t pan_nap = FALSE;
+ bool pan_nap = false;
if (strcmp(name, "UUIDs") != 0)
return;
pan = g_hash_table_lookup(networks, g_dbus_proxy_get_path(proxy));
- if (pan == NULL)
+ if (!pan)
return;
- if (pan->network != NULL &&
- connman_network_get_device(pan->network) != NULL)
- pan_nap = TRUE;
+ if (pan->network &&
+ connman_network_get_device(pan->network))
+ pan_nap = true;
DBG("network %p network nap %d proxy nap %d", pan->network, pan_nap,
proxy_get_nap(pan->btdevice_proxy));
@@ -394,12 +402,12 @@ static void pan_free(gpointer data)
{
struct bluetooth_pan *pan = data;
- if (pan->btnetwork_proxy != NULL) {
+ if (pan->btnetwork_proxy) {
g_dbus_proxy_unref(pan->btnetwork_proxy);
pan->btnetwork_proxy = NULL;
}
- if (pan->btdevice_proxy != NULL) {
+ if (pan->btdevice_proxy) {
g_dbus_proxy_unref(pan->btdevice_proxy);
pan->btdevice_proxy = NULL;
}
@@ -416,7 +424,7 @@ static void pan_create(GDBusProxy *network_proxy)
pan = g_try_new0(struct bluetooth_pan, 1);
- if (pan == NULL) {
+ if (!pan) {
connman_error("Out of memory creating PAN NAP");
return;
}
@@ -427,7 +435,7 @@ static void pan_create(GDBusProxy *network_proxy)
pan->btdevice_proxy = g_dbus_proxy_new(client, path,
"org.bluez.Device1");
- if (pan->btdevice_proxy == NULL) {
+ if (!pan->btdevice_proxy) {
connman_error("Cannot create BT PAN watcher %s", path);
g_hash_table_remove(networks, path);
return;
@@ -453,31 +461,16 @@ static struct connman_network_driver network_driver = {
.disconnect = bluetooth_pan_disconnect,
};
-static void device_enable_cb(const DBusError *error, void *user_data)
+static void enable_device(struct connman_device *device, const char *path)
{
- char *path = user_data;
- struct connman_device *device;
GHashTableIter iter;
gpointer key, value;
- device = g_hash_table_lookup(devices, path);
- if (device == NULL) {
- DBG("device already removed");
- goto out;
- }
-
- if (dbus_error_is_set(error) == TRUE) {
- connman_warn("Bluetooth device %s not enabled %s",
- path, error->message);
- goto out;
- }
-
DBG("device %p %s", device, path);
-
- connman_device_set_powered(device, TRUE);
+ connman_device_set_powered(device, true);
g_hash_table_iter_init(&iter, networks);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
struct bluetooth_pan *pan = value;
if (g_strcmp0(proxy_get_string(pan->btdevice_proxy, "Adapter"),
@@ -487,7 +480,26 @@ static void device_enable_cb(const DBusError *error, void *user_data)
pan_create_nap(pan);
}
}
+}
+static void device_enable_cb(const DBusError *error, void *user_data)
+{
+ char *path = user_data;
+ struct connman_device *device;
+
+ device = g_hash_table_lookup(devices, path);
+ if (!device) {
+ DBG("device already removed");
+ goto out;
+ }
+
+ if (dbus_error_is_set(error)) {
+ connman_warn("Bluetooth device %s not enabled %s",
+ path, error->message);
+ goto out;
+ }
+
+ enable_device(device, path);
out:
g_free(path);
}
@@ -495,15 +507,15 @@ out:
static int bluetooth_device_enable(struct connman_device *device)
{
GDBusProxy *proxy = connman_device_get_data(device);
- connman_bool_t device_powered = TRUE;
+ dbus_bool_t device_powered = TRUE;
const char *path;
- if (proxy == NULL)
+ if (!proxy)
return 0;
path = g_dbus_proxy_get_path(proxy);
- if (proxy_get_bool(proxy, "Powered") == TRUE) {
+ if (proxy_get_bool(proxy, "Powered")) {
DBG("already enabled %p %s", device, path);
return -EALREADY;
}
@@ -517,37 +529,44 @@ static int bluetooth_device_enable(struct connman_device *device)
return -EINPROGRESS;
}
+static void disable_device(struct connman_device *device, const char *path)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ DBG("device %p %s", device, path);
+ connman_device_set_powered(device, false);
+
+ g_hash_table_iter_init(&iter, networks);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ struct bluetooth_pan *pan = value;
+
+ if (pan->network && connman_network_get_device(pan->network)
+ == device) {
+ DBG("disable network %p", pan->network);
+ connman_device_remove_network(device, pan->network);
+ }
+ }
+}
+
static void device_disable_cb(const DBusError *error, void *user_data)
{
char *path = user_data;
struct connman_device *device;
- GHashTableIter iter;
- gpointer key, value;
device = g_hash_table_lookup(devices, path);
- if (device == NULL) {
+ if (!device) {
DBG("device already removed");
goto out;
}
- if (dbus_error_is_set(error) == TRUE) {
+ if (dbus_error_is_set(error)) {
connman_warn("Bluetooth device %s not disabled: %s",
path, error->message);
goto out;
}
- DBG("device %p %s", device, path);
- connman_device_set_powered(device, FALSE);
-
- g_hash_table_iter_init(&iter, networks);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
- struct bluetooth_pan *pan = value;
-
- if (connman_network_get_device(pan->network) == device) {
- DBG("disable network %p", pan->network);
- connman_device_remove_network(device, pan->network);
- }
- }
+ disable_device(device, path);
out:
g_free(path);
@@ -556,15 +575,15 @@ out:
static int bluetooth_device_disable(struct connman_device *device)
{
GDBusProxy *proxy = connman_device_get_data(device);
- connman_bool_t device_powered = FALSE;
+ dbus_bool_t device_powered = FALSE;
const char *path;
- if (proxy == NULL)
+ if (!proxy)
return 0;
path = g_dbus_proxy_get_path(proxy);
- if (proxy_get_bool(proxy, "Powered") == FALSE) {
+ if (!proxy_get_bool(proxy, "Powered")) {
DBG("already disabled %p %s", device, path);
return -EALREADY;
}
@@ -583,7 +602,7 @@ static void adapter_property_change(GDBusProxy *proxy, const char *name,
{
struct connman_device *device;
const char *path;
- connman_bool_t adapter_powered, device_powered;
+ bool adapter_powered, device_powered;
if (strcmp(name, "Powered") != 0)
return;
@@ -598,11 +617,10 @@ static void adapter_property_change(GDBusProxy *proxy, const char *name,
device_powered, adapter_powered);
if (device_powered != adapter_powered) {
- DBG("powering adapter");
- if (device_powered == TRUE)
- bluetooth_device_enable(device);
+ if (adapter_powered)
+ enable_device(device, path);
else
- bluetooth_device_disable(device);
+ disable_device(device, path);
}
}
@@ -612,7 +630,7 @@ static void device_free(gpointer data)
GDBusProxy *proxy = connman_device_get_data(device);
connman_device_set_data(device, NULL);
- if (proxy != NULL)
+ if (proxy)
g_dbus_proxy_unref(proxy);
connman_device_unregister(device);
@@ -622,7 +640,7 @@ static void device_free(gpointer data)
struct tethering_info {
struct connman_technology *technology;
char *bridge;
- connman_bool_t enable;
+ bool enable;
};
static void tethering_free(void *user_data)
@@ -641,15 +659,15 @@ static void tethering_create_cb(DBusMessage *message, void *user_data)
const char *dbus_error = dbus_message_get_error_name(message);
DBG("%s tethering failed: %s",
- tethering->enable == TRUE? "enable": "disable",
+ tethering->enable ? "enable" : "disable",
dbus_error);
return;
}
- DBG("bridge %s %s", tethering->bridge, tethering->enable == TRUE?
+ DBG("bridge %s %s", tethering->bridge, tethering->enable ?
"enabled": "disabled");
- if (tethering->technology != NULL)
+ if (tethering->technology)
connman_technology_tethering_notify(tethering->technology,
tethering->enable);
}
@@ -660,28 +678,28 @@ static void tethering_append(DBusMessageIter *iter, void *user_data)
const char *nap = "nap";
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &nap);
- if (tethering->enable == TRUE)
+ if (tethering->enable)
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
&tethering->bridge);
}
-static connman_bool_t tethering_create(const char *path,
+static bool tethering_create(const char *path,
struct connman_technology *technology, const char *bridge,
- connman_bool_t enabled)
+ bool enabled)
{
struct tethering_info *tethering = g_new0(struct tethering_info, 1);
GDBusProxy *proxy;
const char *method;
- connman_bool_t result;
+ bool result;
DBG("path %s bridge %s", path, bridge);
- if (bridge == NULL)
+ if (!bridge)
return -EINVAL;
proxy = g_dbus_proxy_new(client, path, "org.bluez.NetworkServer1");
- if (proxy == NULL)
- return FALSE;
+ if (!proxy)
+ return false;
tethering->technology = technology;
tethering->bridge = g_strdup(bridge);
@@ -706,17 +724,17 @@ static void device_create(GDBusProxy *proxy)
const char *path = g_dbus_proxy_get_path(proxy);
const char *address;
char ident[BLUETOOTH_ADDR_LEN * 2 + 1];
- connman_bool_t powered;
+ bool powered;
address = proxy_get_string(proxy, "Address");
- if (address == NULL)
+ if (!address)
return;
address2ident(address, ident);
device = connman_device_create("bluetooth",
CONNMAN_DEVICE_TYPE_BLUETOOTH);
- if (device == NULL)
+ if (!device)
return;
connman_device_set_data(device, g_dbus_proxy_ref(proxy));
@@ -738,8 +756,8 @@ static void device_create(GDBusProxy *proxy)
powered = proxy_get_bool(proxy, "Powered");
connman_device_set_powered(device, powered);
- if (proxy_get_nap(proxy) == TRUE && bluetooth_tethering == FALSE)
- tethering_create(path, NULL, NULL, FALSE);
+ if (proxy_get_nap(proxy) && !bluetooth_tethering)
+ tethering_create(path, NULL, NULL, false);
}
static void object_added(GDBusProxy *proxy, void *user_data)
@@ -747,6 +765,11 @@ static void object_added(GDBusProxy *proxy, void *user_data)
const char *interface;
interface = g_dbus_proxy_get_interface(proxy);
+ if (!interface) {
+ connman_warn("Interface or proxy missing when adding "
+ "bluetooth object");
+ return;
+ }
if (strcmp(interface, "org.bluez.Adapter1") == 0) {
DBG("%s %s", interface, g_dbus_proxy_get_path(proxy));
@@ -766,6 +789,11 @@ static void object_removed(GDBusProxy *proxy, void *user_data)
const char *interface, *path;
interface = g_dbus_proxy_get_interface(proxy);
+ if (!interface) {
+ connman_warn("Interface or proxy missing when removing "
+ "bluetooth object");
+ return;
+ }
if (strcmp(interface, "org.bluez.Adapter1") == 0) {
path = g_dbus_proxy_get_path(proxy);
@@ -790,7 +818,7 @@ static int bluetooth_device_probe(struct connman_device *device)
g_hash_table_iter_init(&iter, devices);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
struct connman_device *known = value;
if (device == known)
@@ -826,7 +854,7 @@ static void bluetooth_tech_remove(struct connman_technology *technology)
static int bluetooth_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)
{
GHashTableIter hash_iter;
gpointer key, value;
@@ -836,18 +864,18 @@ static int bluetooth_tech_set_tethering(struct connman_technology *technology,
g_hash_table_iter_init(&hash_iter, devices);
- while (g_hash_table_iter_next(&hash_iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&hash_iter, &key, &value)) {
const char *path = key;
struct connman_device *device = value;
DBG("device %p", device);
if (tethering_create(path, technology, bridge, enabled)
- == TRUE)
+ )
i++;
}
- DBG("%s %d device(s)", enabled == TRUE? "enabled": "disabled", i);
+ DBG("%s %d device(s)", enabled ? "enabled" : "disabled", i);
if (i == 0)
return -ENODEV;
@@ -866,7 +894,7 @@ static struct connman_technology_driver tech_driver = {
static int bluetooth_init(void)
{
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
goto out;
if (connman_technology_driver_register(&tech_driver) < 0) {
@@ -894,7 +922,7 @@ static int bluetooth_init(void)
pan_free);
client = g_dbus_client_new(connection, BLUEZ_SERVICE, BLUEZ_PATH);
- if (client == NULL) {
+ if (!client) {
connman_warn("Failed to initialize D-Bus client for "
BLUEZ_SERVICE);
goto out;
@@ -906,16 +934,16 @@ static int bluetooth_init(void)
return 0;
out:
- if (networks != NULL)
+ if (networks)
g_hash_table_destroy(networks);
- if (devices != NULL)
+ if (devices)
g_hash_table_destroy(devices);
- if (client != NULL)
+ if (client)
g_dbus_client_unref(client);
- if (connection != NULL)
+ if (connection)
dbus_connection_unref(connection);
return -EIO;
@@ -923,6 +951,12 @@ out:
static void bluetooth_exit(void)
{
+ /*
+ * We unset the disabling of the Bluetooth device when shutting down
+ * so that non-PAN BT connections are not affected.
+ */
+ device_driver.disable = NULL;
+
connman_network_driver_unregister(&network_driver);
g_hash_table_destroy(networks);
diff --git a/plugins/bluetooth_legacy.c b/plugins/bluetooth_legacy.c
index 41438f44..2d7a9e01 100644
--- a/plugins/bluetooth_legacy.c
+++ b/plugins/bluetooth_legacy.c
@@ -2,7 +2,7 @@
*
* 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
@@ -77,7 +77,7 @@ static int pan_probe(struct connman_network *network)
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)
@@ -98,29 +98,33 @@ static void pan_remove(struct connman_network *network)
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
@@ -128,7 +132,7 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
goto err;
}
- if (interface == NULL)
+ if (!interface)
goto err;
DBG("interface %s", interface);
@@ -137,7 +141,7 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
connman_network_set_index(network, index);
- connman_network_set_connected(network, TRUE);
+ connman_network_set_connected(network, true);
dbus_message_unref(reply);
@@ -146,7 +150,7 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
return;
err:
- connman_network_set_connected(network, FALSE);
+ connman_network_set_connected(network, false);
dbus_message_unref(reply);
@@ -162,12 +166,12 @@ static int pan_connect(struct connman_network *network)
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);
@@ -175,20 +179,21 @@ static int pan_connect(struct connman_network *network)
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);
@@ -197,24 +202,29 @@ static int pan_connect(struct connman_network *network)
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
@@ -222,7 +232,7 @@ static void disconnect_reply(DBusPendingCall *call, void *user_data)
goto done;
}
- connman_network_set_connected(network, FALSE);
+ connman_network_set_connected(network, false);
done:
dbus_message_unref(reply);
@@ -240,26 +250,26 @@ static int pan_disconnect(struct connman_network *network)
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;
@@ -267,9 +277,10 @@ static int pan_disconnect(struct connman_network *network)
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);
@@ -297,10 +308,10 @@ static gboolean network_changed(DBusConnection *conn,
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);
@@ -308,16 +319,16 @@ static gboolean network_changed(DBusConnection *conn,
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;
@@ -334,7 +345,7 @@ static void extract_properties(DBusMessage *reply, const char **parent,
{
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)
@@ -352,29 +363,29 @@ static void extract_properties(DBusMessage *reply, const char **parent,
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));
}
@@ -421,14 +432,14 @@ static void network_properties_reply(DBusPendingCall *call, void *user_data)
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);
@@ -441,16 +452,16 @@ static void network_properties_reply(DBusPendingCall *call, void *user_data)
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);
@@ -478,18 +489,18 @@ static void add_network(const char *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;
}
@@ -526,10 +537,10 @@ static void check_pending_networks(const char *adapter)
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);
@@ -549,10 +560,10 @@ static gboolean adapter_changed(DBusConnection *conn,
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);
@@ -560,19 +571,20 @@ static gboolean adapter_changed(DBusConnection *conn,
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);
}
@@ -589,17 +601,17 @@ static gboolean device_removed(DBusConnection *conn,
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);
@@ -616,7 +628,7 @@ static gboolean device_changed(DBusConnection *conn,
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);
@@ -626,7 +638,7 @@ static gboolean device_changed(DBusConnection *conn,
DBG("key %s", key);
- if (g_str_equal(key, "UUIDs") == TRUE)
+ if (g_str_equal(key, "UUIDs"))
add_network(path);
return TRUE;
@@ -639,12 +651,12 @@ static void remove_device_networks(struct connman_device *device)
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)
@@ -653,7 +665,7 @@ static void remove_device_networks(struct connman_device *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);
@@ -682,7 +694,7 @@ static void add_pending_networks(const char *adapter, DBusMessageIter *array)
dbus_message_iter_next(&value);
}
- if (list == NULL)
+ if (!list)
return;
g_hash_table_replace(pending_networks, g_strdup(adapter), list);
@@ -703,20 +715,20 @@ static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
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);
@@ -731,7 +743,7 @@ static void adapter_properties_reply(DBusPendingCall *call, void *user_data)
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);
@@ -752,9 +764,10 @@ update:
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
@@ -775,18 +788,17 @@ static void add_adapter(DBusConnection *conn, const char *path)
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;
}
@@ -841,17 +853,16 @@ static void list_adapters_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);
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
@@ -890,7 +901,7 @@ static void remove_network(gpointer data)
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);
@@ -921,18 +932,17 @@ static void bluetooth_connect(DBusConnection *conn, void *user_data)
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;
}
@@ -947,7 +957,7 @@ static void bluetooth_disconnect(DBusConnection *conn, void *user_data)
{
DBG("connection %p", conn);
- if (bluetooth_devices == NULL)
+ if (!bluetooth_devices)
return;
g_hash_table_destroy(bluetooth_networks);
@@ -965,12 +975,12 @@ static int bluetooth_probe(struct connman_device *device)
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)
@@ -996,7 +1006,7 @@ static void powered_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);
@@ -1019,12 +1029,12 @@ static int change_powered(DBusConnection *conn, const char *path,
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);
@@ -1033,14 +1043,13 @@ static int change_powered(DBusConnection *conn, const char *path,
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;
@@ -1102,7 +1111,7 @@ static void server_register_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);
@@ -1113,7 +1122,7 @@ static void server_register_reply(DBusPendingCall *call, void *user_data)
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)
@@ -1128,7 +1137,7 @@ 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);
@@ -1139,13 +1148,13 @@ static void server_unregister_reply(DBusPendingCall *call, void *user_data)
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;
@@ -1157,7 +1166,7 @@ static void server_register(const char *path, const char *uuid,
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);
@@ -1165,24 +1174,24 @@ static void server_register(const char *path, const char *uuid,
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
@@ -1207,7 +1216,7 @@ static void enable_nap(gpointer key, gpointer value, gpointer user_data)
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)
@@ -1220,12 +1229,12 @@ 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,
@@ -1234,6 +1243,9 @@ static int tech_set_tethering(struct connman_technology *technology,
DBG("bridge %s", bridge);
+ if (!bluetooth_devices)
+ return -ENOTCONN;
+
if (enabled)
g_hash_table_foreach(bluetooth_devices, enable_nap, &info);
else
@@ -1264,7 +1276,7 @@ static int bluetooth_init(void)
int err;
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
watch = g_dbus_add_service_watch(connection, BLUEZ_SERVICE,
@@ -1352,6 +1364,12 @@ static void bluetooth_exit(void)
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);
diff --git a/plugins/dundee.c b/plugins/dundee.c
index 6de8680f..b72c69e5 100644
--- a/plugins/dundee.c
+++ b/plugins/dundee.c
@@ -61,7 +61,7 @@ struct dundee_data {
struct connman_device *device;
struct connman_network *network;
- connman_bool_t active;
+ bool active;
int index;
@@ -81,7 +81,7 @@ static char *get_ident(const char *path)
return NULL;
pos = strrchr(path, '/');
- if (pos == NULL)
+ if (!pos)
return NULL;
return pos + 1;
@@ -97,7 +97,7 @@ static int create_device(struct dundee_data *info)
ident = g_strdup(get_ident(info->path));
device = connman_device_create("dundee", CONNMAN_DEVICE_TYPE_BLUETOOTH);
- if (device == NULL) {
+ if (!device) {
err = -ENOMEM;
goto out;
}
@@ -126,12 +126,12 @@ out:
static void destroy_device(struct dundee_data *info)
{
- connman_device_set_powered(info->device, FALSE);
+ connman_device_set_powered(info->device, false);
- if (info->call != NULL)
+ if (info->call)
dbus_pending_call_cancel(info->call);
- if (info->network != NULL) {
+ if (info->network) {
connman_device_remove_network(info->device, info->network);
connman_network_unref(info->network);
info->network = NULL;
@@ -147,7 +147,7 @@ static void device_destroy(gpointer data)
{
struct dundee_data *info = data;
- if (info->device != NULL)
+ if (info->device)
destroy_device(info);
g_free(info->path);
@@ -166,7 +166,7 @@ static int create_network(struct dundee_data *info)
network = connman_network_create(info->path,
CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN);
- if (network == NULL)
+ if (!network)
return -ENOMEM;
DBG("network %p", network);
@@ -201,7 +201,7 @@ static void set_connected(struct dundee_data *info)
connman_inet_ifup(info->index);
service = connman_service_lookup_from_network(info->network);
- if (service == NULL)
+ if (!service)
return;
connman_service_create_ip4config(service, info->index);
@@ -211,14 +211,14 @@ static void set_connected(struct dundee_data *info)
connman_network_set_ipaddress(info->network, info->address);
connman_network_set_nameservers(info->network, info->nameservers);
- connman_network_set_connected(info->network, TRUE);
+ connman_network_set_connected(info->network, true);
}
static void set_disconnected(struct dundee_data *info)
{
DBG("%s", info->path);
- connman_network_set_connected(info->network, FALSE);
+ connman_network_set_connected(info->network, false);
connman_inet_ifdown(info->index);
}
@@ -260,21 +260,21 @@ static int set_property(struct dundee_data *info,
message = dbus_message_new_method_call(DUNDEE_SERVICE, info->path,
DUNDEE_DEVICE_INTERFACE, SET_PROPERTY);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
connman_dbus_property_append_basic(&iter, property, type, value);
- if (dbus_connection_send_with_reply(connection, message,
- &info->call, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &info->call, TIMEOUT)) {
connman_error("Failed to change property: %s %s",
info->path, property);
dbus_message_unref(message);
return -EINVAL;
}
- if (info->call == NULL) {
+ if (!info->call) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
@@ -359,12 +359,12 @@ static int dundee_probe(struct connman_device *device)
DBG("device %p", device);
- if (dundee_devices == NULL)
+ if (!dundee_devices)
return -ENOTSUP;
g_hash_table_iter_init(&iter, dundee_devices);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
struct dundee_data *info = value;
if (device == info->device)
@@ -415,7 +415,7 @@ static char *extract_nameservers(DBusMessageIter *array)
dbus_message_iter_get_basic(&entry, &nameserver);
- if (nameservers == NULL) {
+ if (!nameservers) {
nameservers = g_strdup(nameserver);
} else {
tmp = nameservers;
@@ -453,7 +453,7 @@ static void extract_settings(DBusMessageIter *array,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Interface") == TRUE) {
+ if (g_str_equal(key, "Interface")) {
dbus_message_iter_get_basic(&value, &interface);
DBG("Interface %s", interface);
@@ -464,17 +464,17 @@ static void extract_settings(DBusMessageIter *array,
if (index < 0)
break;
- } else if (g_str_equal(key, "Address") == TRUE) {
+ } else if (g_str_equal(key, "Address")) {
dbus_message_iter_get_basic(&value, &val);
address = g_strdup(val);
DBG("Address %s", address);
- } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
+ } else if (g_str_equal(key, "DomainNameServers")) {
nameservers = extract_nameservers(&value);
DBG("Nameservers %s", nameservers);
- } else if (g_str_equal(key, "Gateway") == TRUE) {
+ } else if (g_str_equal(key, "Gateway")) {
dbus_message_iter_get_basic(&value, &val);
gateway = g_strdup(val);
@@ -489,7 +489,7 @@ static void extract_settings(DBusMessageIter *array,
goto out;
info->address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
- if (info->address == NULL)
+ if (!info->address)
goto out;
info->index = index;
@@ -516,16 +516,16 @@ static gboolean device_changed(DBusConnection *conn,
const char *signature = DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_VARIANT_AS_STRING;
- if (dbus_message_has_signature(message, signature) == FALSE) {
+ if (!dbus_message_has_signature(message, signature)) {
connman_error("dundee signature does not match");
return TRUE;
}
info = g_hash_table_lookup(dundee_devices, path);
- if (info == NULL)
+ if (!info)
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);
@@ -538,20 +538,23 @@ static gboolean device_changed(DBusConnection *conn,
* Active. Settings will always be send before Active = True.
* That means we don't have to order here.
*/
- if (g_str_equal(key, "Active") == TRUE) {
- dbus_message_iter_get_basic(&value, &info->active);
+ if (g_str_equal(key, "Active")) {
+ dbus_bool_t active;
+
+ dbus_message_iter_get_basic(&value, &active);
+ info->active = active;
DBG("%s Active %d", info->path, info->active);
- if (info->active == TRUE)
+ if (info->active)
set_connected(info);
else
set_disconnected(info);
- } else if (g_str_equal(key, "Settings") == TRUE) {
+ } else if (g_str_equal(key, "Settings")) {
DBG("%s Settings", info->path);
extract_settings(&value, info);
- } else if (g_str_equal(key, "Name") == TRUE) {
+ } else if (g_str_equal(key, "Name")) {
char *name;
dbus_message_iter_get_basic(&value, &name);
@@ -574,11 +577,11 @@ static void add_device(const char *path, DBusMessageIter *properties)
int err;
info = g_hash_table_lookup(dundee_devices, path);
- if (info != NULL)
+ if (info)
return;
info = g_try_new0(struct dundee_data, 1);
- if (info == NULL)
+ if (!info)
return;
info->path = g_strdup(path);
@@ -594,15 +597,18 @@ static void add_device(const char *path, DBusMessageIter *properties)
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Active") == TRUE) {
- dbus_message_iter_get_basic(&value, &info->active);
+ if (g_str_equal(key, "Active")) {
+ dbus_bool_t active;
+
+ dbus_message_iter_get_basic(&value, &active);
+ info->active = active;
DBG("%s Active %d", info->path, info->active);
- } else if (g_str_equal(key, "Settings") == TRUE) {
+ } else if (g_str_equal(key, "Settings")) {
DBG("%s Settings", info->path);
extract_settings(&value, info);
- } else if (g_str_equal(key, "Name") == TRUE) {
+ } else if (g_str_equal(key, "Name")) {
char *name;
dbus_message_iter_get_basic(&value, &name);
@@ -627,7 +633,7 @@ static void add_device(const char *path, DBusMessageIter *properties)
goto out;
}
- if (info->active == TRUE)
+ if (info->active)
set_connected(info);
return;
@@ -648,14 +654,14 @@ static gboolean device_added(DBusConnection *conn, DBusMessage *message,
DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
- if (dbus_message_has_signature(message, signature) == FALSE) {
+ if (!dbus_message_has_signature(message, signature)) {
connman_error("dundee signature does not match");
return TRUE;
}
DBG("");
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &path);
@@ -681,7 +687,7 @@ static gboolean device_removed(DBusConnection *conn, DBusMessage *message,
const char *path;
const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
- if (dbus_message_has_signature(message, signature) == FALSE) {
+ if (!dbus_message_has_signature(message, signature)) {
connman_error("dundee signature does not match");
return TRUE;
}
@@ -711,20 +717,20 @@ static void manager_get_devices_reply(DBusPendingCall *call, void *user_data)
reply = dbus_pending_call_steal_reply(call);
- if (dbus_message_has_signature(reply, signature) == FALSE) {
+ if (!dbus_message_has_signature(reply, signature)) {
connman_error("dundee signature does not match");
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_iter_init(reply, &array) == FALSE)
+ if (!dbus_message_iter_init(reply, &array))
goto done;
dbus_message_iter_recurse(&array, &dict);
@@ -759,17 +765,17 @@ static int manager_get_devices(void)
message = dbus_message_new_method_call(DUNDEE_SERVICE, "/",
DUNDEE_MANAGER_INTERFACE, GET_DEVICES);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
- 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 call GetDevices()");
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
@@ -811,7 +817,7 @@ static int dundee_init(void)
int err;
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
watch = g_dbus_add_service_watch(connection, DUNDEE_SERVICE,
diff --git a/plugins/ethernet.c b/plugins/ethernet.c
index bafc75dd..b8e52ce0 100644
--- a/plugins/ethernet.c
+++ b/plugins/ethernet.c
@@ -2,7 +2,7 @@
*
* 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
@@ -41,7 +41,7 @@
#include <connman/log.h>
#include <connman/setting.h>
-static connman_bool_t eth_tethering = FALSE;
+static bool eth_tethering = false;
struct ethernet_data {
int index;
@@ -50,43 +50,43 @@ struct ethernet_data {
struct connman_network *network;
};
-static int cable_probe(struct connman_network *network)
+static int eth_network_probe(struct connman_network *network)
{
DBG("network %p", network);
return 0;
}
-static void cable_remove(struct connman_network *network)
+static void eth_network_remove(struct connman_network *network)
{
DBG("network %p", network);
}
-static int cable_connect(struct connman_network *network)
+static int eth_network_connect(struct connman_network *network)
{
DBG("network %p", network);
- connman_network_set_connected(network, TRUE);
+ connman_network_set_connected(network, true);
return 0;
}
-static int cable_disconnect(struct connman_network *network)
+static int eth_network_disconnect(struct connman_network *network)
{
DBG("network %p", network);
- connman_network_set_connected(network, FALSE);
+ connman_network_set_connected(network, false);
return 0;
}
-static struct connman_network_driver cable_driver = {
+static struct connman_network_driver eth_network_driver = {
.name = "cable",
.type = CONNMAN_NETWORK_TYPE_ETHERNET,
- .probe = cable_probe,
- .remove = cable_remove,
- .connect = cable_connect,
- .disconnect = cable_disconnect,
+ .probe = eth_network_probe,
+ .remove = eth_network_remove,
+ .connect = eth_network_connect,
+ .disconnect = eth_network_disconnect,
};
static void add_network(struct connman_device *device,
@@ -97,7 +97,7 @@ static void add_network(struct connman_device *device,
network = connman_network_create("carrier",
CONNMAN_NETWORK_TYPE_ETHERNET);
- if (network == NULL)
+ if (!network)
return;
index = connman_device_get_index(device);
@@ -110,7 +110,7 @@ static void add_network(struct connman_device *device,
return;
}
- if (eth_tethering == FALSE)
+ if (!eth_tethering)
/*
* Prevent service from starting the reconnect
* procedure as we do not want the DHCP client
@@ -124,7 +124,7 @@ static void add_network(struct connman_device *device,
static void remove_network(struct connman_device *device,
struct ethernet_data *ethernet)
{
- if (ethernet->network == NULL)
+ if (!ethernet->network)
return;
connman_device_remove_network(device, ethernet->network);
@@ -143,10 +143,10 @@ static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
if ((ethernet->flags & IFF_UP) != (flags & IFF_UP)) {
if (flags & IFF_UP) {
DBG("power on");
- connman_device_set_powered(device, TRUE);
+ connman_device_set_powered(device, true);
} else {
DBG("power off");
- connman_device_set_powered(device, FALSE);
+ connman_device_set_powered(device, false);
}
}
@@ -163,14 +163,14 @@ static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
ethernet->flags = flags;
}
-static int ethernet_probe(struct connman_device *device)
+static int eth_dev_probe(struct connman_device *device)
{
struct ethernet_data *ethernet;
DBG("device %p", device);
ethernet = g_try_new0(struct ethernet_data, 1);
- if (ethernet == NULL)
+ if (!ethernet)
return -ENOMEM;
connman_device_set_data(device, ethernet);
@@ -184,7 +184,7 @@ static int ethernet_probe(struct connman_device *device)
return 0;
}
-static void ethernet_remove(struct connman_device *device)
+static void eth_dev_remove(struct connman_device *device)
{
struct ethernet_data *ethernet = connman_device_get_data(device);
@@ -199,7 +199,7 @@ static void ethernet_remove(struct connman_device *device)
g_free(ethernet);
}
-static int ethernet_enable(struct connman_device *device)
+static int eth_dev_enable(struct connman_device *device)
{
struct ethernet_data *ethernet = connman_device_get_data(device);
@@ -208,7 +208,7 @@ static int ethernet_enable(struct connman_device *device)
return connman_inet_ifup(ethernet->index);
}
-static int ethernet_disable(struct connman_device *device)
+static int eth_dev_disable(struct connman_device *device)
{
struct ethernet_data *ethernet = connman_device_get_data(device);
@@ -217,133 +217,40 @@ static int ethernet_disable(struct connman_device *device)
return connman_inet_ifdown(ethernet->index);
}
-static struct connman_device_driver ethernet_driver = {
+static struct connman_device_driver eth_dev_driver = {
.name = "ethernet",
.type = CONNMAN_DEVICE_TYPE_ETHERNET,
- .probe = ethernet_probe,
- .remove = ethernet_remove,
- .enable = ethernet_enable,
- .disable = ethernet_disable,
+ .probe = eth_dev_probe,
+ .remove = eth_dev_remove,
+ .enable = eth_dev_enable,
+ .disable = eth_dev_disable,
};
-static GList *cdc_interface_list = NULL;
-
-static void tech_add_interface(struct connman_technology *technology,
- int index, const char *name, const char *ident)
-{
- DBG("index %d name %s ident %s", index, name, ident);
-
- if (g_list_find(cdc_interface_list,
- GINT_TO_POINTER((int) index)) != NULL)
- return;
-
- cdc_interface_list = g_list_prepend(cdc_interface_list,
- (GINT_TO_POINTER((int) index)));
-}
-
-static void tech_remove_interface(struct connman_technology *technology,
- int index)
-{
- DBG("index %d", index);
-
- cdc_interface_list = g_list_remove(cdc_interface_list,
- GINT_TO_POINTER((int) index));
-}
-
-static void enable_tethering(struct connman_technology *technology,
- const char *bridge)
-{
- GList *list;
-
- for (list = cdc_interface_list; list; list = list->next) {
- int index = GPOINTER_TO_INT(list->data);
-
- connman_technology_tethering_notify(technology, TRUE);
-
- connman_inet_ifup(index);
-
- connman_inet_add_to_bridge(index, bridge);
- }
-}
-
-static void disable_tethering(struct connman_technology *technology,
- const char *bridge)
-{
- GList *list;
-
- for (list = cdc_interface_list; list; list = list->next) {
- int index = GPOINTER_TO_INT(list->data);
-
- connman_inet_remove_from_bridge(index, bridge);
-
- connman_inet_ifdown(index);
-
- connman_technology_tethering_notify(technology, FALSE);
- }
-}
-
-static int tech_set_tethering(struct connman_technology *technology,
- const char *identifier, const char *passphrase,
- const char *bridge, connman_bool_t enabled)
-{
- DBG("bridge %s enabled %d", bridge, enabled);
-
- if (enabled)
- enable_tethering(technology, bridge);
- else
- disable_tethering(technology, bridge);
-
- return 0;
-}
-
-static int tech_probe(struct connman_technology *technology)
+static int eth_tech_probe(struct connman_technology *technology)
{
return 0;
}
-static void tech_remove(struct connman_technology *technology)
-{
- g_list_free(cdc_interface_list);
-
- cdc_interface_list = NULL;
-}
-
-static struct connman_technology_driver tech_driver = {
- .name = "cdc_ethernet",
- .type = CONNMAN_SERVICE_TYPE_GADGET,
- .probe = tech_probe,
- .remove = tech_remove,
- .add_interface = tech_add_interface,
- .remove_interface = tech_remove_interface,
- .set_tethering = tech_set_tethering,
-};
-
-static int eth_probe(struct connman_technology *technology)
-{
- return 0;
-}
-
-static void eth_remove(struct connman_technology *technology)
+static void eth_tech_remove(struct connman_technology *technology)
{
DBG("");
}
static GList *eth_interface_list = NULL;
-static void eth_add_interface(struct connman_technology *technology,
+static void eth_tech_add_interface(struct connman_technology *technology,
int index, const char *name, const char *ident)
{
DBG("index %d name %s ident %s", index, name, ident);
- if (g_list_find(eth_interface_list,
- GINT_TO_POINTER((int) index)) != NULL)
+ if (g_list_find(eth_interface_list, GINT_TO_POINTER((int)index)))
return;
eth_interface_list = g_list_prepend(eth_interface_list,
(GINT_TO_POINTER((int) index)));
}
-static void eth_remove_interface(struct connman_technology *technology,
+static void eth_tech_remove_interface(struct connman_technology *technology,
int index)
{
DBG("index %d", index);
@@ -352,30 +259,34 @@ static void eth_remove_interface(struct connman_technology *technology,
GINT_TO_POINTER((int) index));
}
-static void eth_enable_tethering(struct connman_technology *technology,
+static void eth_tech_enable_tethering(struct connman_technology *technology,
const char *bridge)
{
GList *list;
+ struct ethernet_data *ethernet;
for (list = eth_interface_list; list; list = list->next) {
int index = GPOINTER_TO_INT(list->data);
struct connman_device *device =
connman_device_find_by_index(index);
- if (device != NULL)
- connman_device_disconnect_service(device);
+ if (device) {
+ ethernet = connman_device_get_data(device);
+ if (ethernet)
+ remove_network(device, ethernet);
+ }
- connman_technology_tethering_notify(technology, TRUE);
+ connman_technology_tethering_notify(technology, true);
connman_inet_ifup(index);
connman_inet_add_to_bridge(index, bridge);
- eth_tethering = TRUE;
+ eth_tethering = true;
}
}
-static void eth_disable_tethering(struct connman_technology *technology,
+static void eth_tech_disable_tethering(struct connman_technology *technology,
const char *bridge)
{
GList *list;
@@ -387,67 +298,58 @@ static void eth_disable_tethering(struct connman_technology *technology,
connman_inet_remove_from_bridge(index, bridge);
- connman_inet_ifdown(index);
+ connman_technology_tethering_notify(technology, false);
- connman_technology_tethering_notify(technology, FALSE);
-
- if (device != NULL)
+ if (device)
connman_device_reconnect_service(device);
- eth_tethering = FALSE;
+ eth_tethering = false;
}
}
-static int eth_set_tethering(struct connman_technology *technology,
+static int eth_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)
{
- if (connman_technology_is_tethering_allowed(
- CONNMAN_SERVICE_TYPE_ETHERNET) == FALSE)
+ if (!connman_technology_is_tethering_allowed(
+ CONNMAN_SERVICE_TYPE_ETHERNET))
return 0;
DBG("bridge %s enabled %d", bridge, enabled);
if (enabled)
- eth_enable_tethering(technology, bridge);
+ eth_tech_enable_tethering(technology, bridge);
else
- eth_disable_tethering(technology, bridge);
+ eth_tech_disable_tethering(technology, bridge);
return 0;
}
-static struct connman_technology_driver eth_driver = {
+static struct connman_technology_driver eth_tech_driver = {
.name = "ethernet",
.type = CONNMAN_SERVICE_TYPE_ETHERNET,
- .probe = eth_probe,
- .remove = eth_remove,
- .add_interface = eth_add_interface,
- .remove_interface = eth_remove_interface,
- .set_tethering = eth_set_tethering,
+ .probe = eth_tech_probe,
+ .remove = eth_tech_remove,
+ .add_interface = eth_tech_add_interface,
+ .remove_interface = eth_tech_remove_interface,
+ .set_tethering = eth_tech_set_tethering,
};
static int ethernet_init(void)
{
int err;
- err = connman_technology_driver_register(&eth_driver);
+ err = connman_technology_driver_register(&eth_tech_driver);
if (err < 0)
return err;
- err = connman_network_driver_register(&cable_driver);
+ err = connman_network_driver_register(&eth_network_driver);
if (err < 0)
return err;
- err = connman_device_driver_register(&ethernet_driver);
- if (err < 0) {
- connman_network_driver_unregister(&cable_driver);
- return err;
- }
-
- err = connman_technology_driver_register(&tech_driver);
+ err = connman_device_driver_register(&eth_dev_driver);
if (err < 0) {
- connman_device_driver_unregister(&ethernet_driver);
- connman_network_driver_unregister(&cable_driver);
+ connman_network_driver_unregister(&eth_network_driver);
return err;
}
@@ -456,13 +358,11 @@ static int ethernet_init(void)
static void ethernet_exit(void)
{
- connman_technology_driver_unregister(&eth_driver);
-
- connman_technology_driver_unregister(&tech_driver);
+ connman_technology_driver_unregister(&eth_tech_driver);
- connman_network_driver_unregister(&cable_driver);
+ connman_network_driver_unregister(&eth_network_driver);
- connman_device_driver_unregister(&ethernet_driver);
+ connman_device_driver_unregister(&eth_dev_driver);
}
CONNMAN_PLUGIN_DEFINE(ethernet, "Ethernet interface plugin", VERSION,
diff --git a/plugins/gadget.c b/plugins/gadget.c
new file mode 100644
index 00000000..94f66487
--- /dev/null
+++ b/plugins/gadget.c
@@ -0,0 +1,358 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2007-2012 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
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <net/if.h>
+
+#ifndef IFF_LOWER_UP
+#define IFF_LOWER_UP 0x10000
+#endif
+
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include <connman/technology.h>
+#include <connman/plugin.h>
+#include <connman/device.h>
+#include <connman/rtnl.h>
+#include <connman/inet.h>
+#include <connman/log.h>
+
+static bool gadget_tethering = false;
+
+struct gadget_data {
+ int index;
+ unsigned flags;
+ unsigned int watch;
+ struct connman_network *network;
+};
+
+static int gadget_network_probe(struct connman_network *network)
+{
+ DBG("network %p", network);
+
+ return 0;
+}
+
+static void gadget_network_remove(struct connman_network *network)
+{
+ DBG("network %p", network);
+}
+
+static int gadget_network_connect(struct connman_network *network)
+{
+ DBG("network %p", network);
+
+ connman_network_set_connected(network, true);
+
+ return 0;
+}
+
+static int gadget_network_disconnect(struct connman_network *network)
+{
+ DBG("network %p", network);
+
+ connman_network_set_connected(network, false);
+
+ return 0;
+}
+
+static struct connman_network_driver gadget_network_driver = {
+ .name = "usb",
+ .type = CONNMAN_NETWORK_TYPE_GADGET,
+ .probe = gadget_network_probe,
+ .remove = gadget_network_remove,
+ .connect = gadget_network_connect,
+ .disconnect = gadget_network_disconnect,
+};
+
+static void add_network(struct connman_device *device,
+ struct gadget_data *gadget)
+{
+ struct connman_network *network;
+ int index;
+
+ network = connman_network_create("gadget",
+ CONNMAN_NETWORK_TYPE_GADGET);
+ if (!network)
+ return;
+
+ index = connman_device_get_index(device);
+ connman_network_set_index(network, index);
+
+ connman_network_set_name(network, "Wired");
+
+ if (connman_device_add_network(device, network) < 0) {
+ connman_network_unref(network);
+ return;
+ }
+
+ if (!gadget_tethering)
+ /*
+ * Prevent service from starting the reconnect
+ * procedure as we do not want the DHCP client
+ * to run when tethering.
+ */
+ connman_network_set_group(network, "usb");
+
+ gadget->network = network;
+}
+
+static void remove_network(struct connman_device *device,
+ struct gadget_data *gadget)
+{
+ if (!gadget->network)
+ return;
+
+ connman_device_remove_network(device, gadget->network);
+ connman_network_unref(gadget->network);
+
+ gadget->network = NULL;
+}
+
+static void gadget_newlink(unsigned flags, unsigned change, void *user_data)
+{
+ struct connman_device *device = user_data;
+ struct gadget_data *gadget = connman_device_get_data(device);
+
+ DBG("index %d flags %d change %d", gadget->index, flags, change);
+
+ if ((gadget->flags & IFF_UP) != (flags & IFF_UP)) {
+ if (flags & IFF_UP) {
+ DBG("power on");
+ connman_device_set_powered(device, true);
+ } else {
+ DBG("power off");
+ connman_device_set_powered(device, false);
+ }
+ }
+
+ if ((gadget->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
+ if (flags & IFF_LOWER_UP) {
+ DBG("carrier on");
+ add_network(device, gadget);
+ } else {
+ DBG("carrier off");
+ remove_network(device, gadget);
+ }
+ }
+
+ gadget->flags = flags;
+}
+
+static int gadget_dev_probe(struct connman_device *device)
+{
+ struct gadget_data *gadget;
+
+ DBG("device %p", device);
+
+ gadget = g_try_new0(struct gadget_data, 1);
+ if (!gadget)
+ return -ENOMEM;
+
+ connman_device_set_data(device, gadget);
+
+ gadget->index = connman_device_get_index(device);
+ gadget->flags = 0;
+
+ gadget->watch = connman_rtnl_add_newlink_watch(gadget->index,
+ gadget_newlink, device);
+
+ return 0;
+}
+
+static void gadget_dev_remove(struct connman_device *device)
+{
+ struct gadget_data *gadget = connman_device_get_data(device);
+
+ DBG("device %p", device);
+
+ connman_device_set_data(device, NULL);
+
+ connman_rtnl_remove_watch(gadget->watch);
+
+ remove_network(device, gadget);
+
+ g_free(gadget);
+}
+
+static int gadget_dev_enable(struct connman_device *device)
+{
+ struct gadget_data *gadget = connman_device_get_data(device);
+
+ DBG("device %p", device);
+
+ return connman_inet_ifup(gadget->index);
+}
+
+static int gadget_dev_disable(struct connman_device *device)
+{
+ struct gadget_data *gadget = connman_device_get_data(device);
+
+ DBG("device %p", device);
+
+ return connman_inet_ifdown(gadget->index);
+}
+
+static struct connman_device_driver gadget_dev_driver = {
+ .name = "gadget",
+ .type = CONNMAN_DEVICE_TYPE_GADGET,
+ .probe = gadget_dev_probe,
+ .remove = gadget_dev_remove,
+ .enable = gadget_dev_enable,
+ .disable = gadget_dev_disable,
+};
+
+static GList *cdc_interface_list = NULL;
+
+static void gadget_tech_add_interface(struct connman_technology *technology,
+ int index, const char *name, const char *ident)
+{
+ DBG("index %d name %s ident %s", index, name, ident);
+
+ if (g_list_find(cdc_interface_list, GINT_TO_POINTER((int)index)))
+ return;
+
+ cdc_interface_list = g_list_prepend(cdc_interface_list,
+ (GINT_TO_POINTER((int) index)));
+}
+
+static void gadget_tech_remove_interface(struct connman_technology *technology,
+ int index)
+{
+ DBG("index %d", index);
+
+ cdc_interface_list = g_list_remove(cdc_interface_list,
+ GINT_TO_POINTER((int) index));
+}
+
+static void gadget_tech_enable_tethering(struct connman_technology *technology,
+ const char *bridge)
+{
+ GList *list;
+
+ for (list = cdc_interface_list; list; list = list->next) {
+ int index = GPOINTER_TO_INT(list->data);
+ struct connman_device *device =
+ connman_device_find_by_index(index);
+ struct gadget_data *gadget;
+
+ if (device) {
+ gadget = connman_device_get_data(device);
+ if (gadget)
+ remove_network(device, gadget);
+ }
+
+ connman_technology_tethering_notify(technology, true);
+
+ connman_inet_ifup(index);
+
+ connman_inet_add_to_bridge(index, bridge);
+ }
+}
+
+static void gadget_tech_disable_tethering(struct connman_technology *technology,
+ const char *bridge)
+{
+ GList *list;
+
+ for (list = cdc_interface_list; list; list = list->next) {
+ int index = GPOINTER_TO_INT(list->data);
+
+ connman_inet_remove_from_bridge(index, bridge);
+
+ connman_inet_ifdown(index);
+
+ connman_technology_tethering_notify(technology, false);
+ }
+}
+
+static int gadget_tech_set_tethering(struct connman_technology *technology,
+ const char *identifier, const char *passphrase,
+ const char *bridge, bool enabled)
+{
+ DBG("bridge %s enabled %d", bridge, enabled);
+
+ if (enabled)
+ gadget_tech_enable_tethering(technology, bridge);
+ else
+ gadget_tech_disable_tethering(technology, bridge);
+
+ return 0;
+}
+
+static int gadget_tech_probe(struct connman_technology *technology)
+{
+ return 0;
+}
+
+static void gadget_tech_remove(struct connman_technology *technology)
+{
+ g_list_free(cdc_interface_list);
+
+ cdc_interface_list = NULL;
+}
+
+static struct connman_technology_driver gadget_tech_driver = {
+ .name = "cdc_ethernet",
+ .type = CONNMAN_SERVICE_TYPE_GADGET,
+ .probe = gadget_tech_probe,
+ .remove = gadget_tech_remove,
+ .add_interface = gadget_tech_add_interface,
+ .remove_interface = gadget_tech_remove_interface,
+ .set_tethering = gadget_tech_set_tethering,
+};
+
+static int gadget_init(void)
+{
+ int err;
+
+ err = connman_technology_driver_register(&gadget_tech_driver);
+ if (err < 0) {
+ return err;
+ }
+
+ err = connman_network_driver_register(&gadget_network_driver);
+ if (err < 0)
+ return err;
+
+ err = connman_device_driver_register(&gadget_dev_driver);
+ if (err < 0) {
+ connman_technology_driver_unregister(&gadget_tech_driver);
+ return err;
+ }
+
+ return 0;
+}
+
+static void gadget_exit(void)
+{
+ connman_technology_driver_unregister(&gadget_tech_driver);
+ connman_network_driver_unregister(&gadget_network_driver);
+ connman_device_driver_unregister(&gadget_dev_driver);
+}
+
+CONNMAN_PLUGIN_DEFINE(gadget, "Gadget interface plugin", VERSION,
+ CONNMAN_PLUGIN_PRIORITY_DEFAULT, gadget_init, gadget_exit)
diff --git a/plugins/hh2serial-gps.c b/plugins/hh2serial-gps.c
index 20521b04..99394e1c 100644
--- a/plugins/hh2serial-gps.c
+++ b/plugins/hh2serial-gps.c
@@ -77,7 +77,7 @@ static int hh2serial_disable(struct connman_device *device)
return 0;
}
-static struct connman_device_driver hh2seial_device_driver = {
+static struct connman_device_driver hh2serial_device_driver = {
.name = "hh2serial GPS",
.type = CONNMAN_DEVICE_TYPE_GPS,
.enable = hh2serial_enable,
@@ -88,24 +88,36 @@ static struct connman_device_driver hh2seial_device_driver = {
static int hh2serial_init(void)
{
- connman_device_driver_register(&hh2seial_device_driver);
+ int err;
+
+ err = connman_device_driver_register(&hh2serial_device_driver);
+ if (err < 0)
+ return err;
hh2serial_device = connman_device_create("hh2serial_gps",
CONNMAN_DEVICE_TYPE_GPS);
- if (hh2serial_device == NULL)
+ if (!hh2serial_device) {
+ connman_device_driver_unregister(&hh2serial_device_driver);
return -ENODEV;
+ }
- connman_device_register(hh2serial_device);
+ err = connman_device_register(hh2serial_device);
+ if (err < 0) {
+ connman_device_unref(hh2serial_device);
+ return err;
+ }
return 0;
}
static void hh2serial_exit(void)
{
- if (hh2serial_device != NULL) {
+ if (hh2serial_device) {
connman_device_unregister(hh2serial_device);
connman_device_unref(hh2serial_device);
}
+
+ connman_device_driver_unregister(&hh2serial_device_driver);
}
CONNMAN_PLUGIN_DEFINE(hh2serial_gps, "hh2serial GPS", VERSION,
diff --git a/plugins/iospm.c b/plugins/iospm.c
index 3b014d31..fcb4cea1 100644
--- a/plugins/iospm.c
+++ b/plugins/iospm.c
@@ -37,21 +37,21 @@
static DBusConnection *connection;
-static void send_indication(const char *path, connman_bool_t enabled)
+static void send_indication(const char *path, bool enabled)
{
DBusMessage *message;
const char *method;
DBG("path %s enabled %d", path, enabled);
- if (enabled == TRUE)
+ if (enabled)
method = "IndicateStart";
else
method = "IndicateStop";
message = dbus_message_new_method_call(IOSPM_SERVICE, path,
IOSPM_INTERFACE, method);
- if (message == NULL)
+ if (!message)
return;
dbus_message_set_no_reply(message, TRUE);
@@ -62,7 +62,7 @@ static void send_indication(const char *path, connman_bool_t enabled)
}
static void iospm_service_enabled(enum connman_service_type type,
- connman_bool_t enabled)
+ bool enabled)
{
switch (type) {
case CONNMAN_SERVICE_TYPE_UNKNOWN:
@@ -73,6 +73,7 @@ static void iospm_service_enabled(enum connman_service_type type,
case CONNMAN_SERVICE_TYPE_GPS:
case CONNMAN_SERVICE_TYPE_VPN:
case CONNMAN_SERVICE_TYPE_GADGET:
+ case CONNMAN_SERVICE_TYPE_P2P:
break;
case CONNMAN_SERVICE_TYPE_BLUETOOTH:
send_indication(IOSPM_BLUETOOTH, enabled);
@@ -80,7 +81,7 @@ static void iospm_service_enabled(enum connman_service_type type,
}
}
-static void iospm_offline_mode(connman_bool_t enabled)
+static void iospm_offline_mode(bool enabled)
{
send_indication(IOSPM_FLIGHT_MODE, enabled);
}
diff --git a/plugins/loopback.c b/plugins/loopback.c
index a111eeed..e113887d 100644
--- a/plugins/loopback.c
+++ b/plugins/loopback.c
@@ -86,7 +86,7 @@ static int setup_hostname(void)
return 0;
}
-static gboolean valid_loopback(int sk, struct ifreq *ifr)
+static bool valid_loopback(int sk, struct ifreq *ifr)
{
struct sockaddr_in *addr;
int err;
@@ -108,24 +108,24 @@ static gboolean valid_loopback(int sk, struct ifreq *ifr)
if (addr->sin_addr.s_addr != loopback_address) {
connman_warn("Invalid loopback address %s",
inet_ntop(AF_INET, &addr->sin_addr, buf, sizeof(buf)));
- return FALSE;
+ return false;
}
err = ioctl(sk, SIOCGIFNETMASK, ifr);
if (err < 0) {
err = -errno;
connman_error("Getting netmask failed (%s)", strerror(-err));
- return TRUE;
+ return true;
}
addr = (struct sockaddr_in *) &ifr->ifr_netmask;
if (addr->sin_addr.s_addr != loopback_netmask) {
connman_warn("Invalid loopback netmask %s",
inet_ntop(AF_INET, &addr->sin_addr, buf, sizeof(buf)));
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
static int setup_loopback(void)
@@ -148,12 +148,12 @@ static int setup_loopback(void)
if (ifr.ifr_flags & IFF_UP) {
connman_info("Checking loopback interface settings");
- if (valid_loopback(sk, &ifr) == TRUE) {
+ if (valid_loopback(sk, &ifr)) {
err = -EALREADY;
goto done;
}
- connman_warn("Correcting wrong lookback settings");
+ connman_warn("Correcting wrong loopback settings");
}
memset(&addr, 0, sizeof(addr));
@@ -215,10 +215,10 @@ static int loopback_set_hostname(const char *hostname)
len = strlen(hostname);
- if (connman_inet_check_hostname(hostname, len) == FALSE)
+ if (!connman_inet_check_hostname(hostname, len))
return -EINVAL;
- if ((ptr = strstr(hostname, ".")) != NULL)
+ if ((ptr = strstr(hostname, ".")))
len = ptr - hostname;
if (sethostname(hostname, len) < 0) {
@@ -238,7 +238,7 @@ static int loopback_set_domainname(const char *domainname)
len = strlen(domainname);
- if (connman_inet_check_hostname(domainname, len) == FALSE)
+ if (!connman_inet_check_hostname(domainname, len))
return -EINVAL;
if (setdomainname(domainname, len) < 0) {
diff --git a/plugins/neard.c b/plugins/neard.c
index 83561fed..1a0fc1cd 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -61,7 +61,7 @@
struct data_elements {
unsigned int value;
unsigned int length;
- gboolean fixed_length;
+ bool fixed_length;
};
typedef enum {
@@ -87,7 +87,7 @@ struct wifi_sc {
static DBusConnection *connection = NULL;
DBusPendingCall *register_call = NULL;
-gboolean agent_registered = FALSE;
+bool agent_registered = false;
static guint watch_id = 0;
static int set_2b_into_tlv(uint8_t *tlv_msg, uint16_t val)
@@ -117,20 +117,20 @@ static uint8_t *encode_to_tlv(const char *ssid, const char *psk, int *length)
uint8_t *tlv_msg;
int pos = 0;
- if (ssid == NULL || length == NULL)
+ if (!ssid || !length)
return NULL;
ssid_len = strlen(ssid);
*length = 6 + 4 + ssid_len;
- if (psk != NULL) {
+ if (psk) {
psk_len = strlen(psk);
*length += 4 + psk_len;
} else
psk_len = 0;
tlv_msg = g_try_malloc0(sizeof(uint8_t) * (*length));
- if (tlv_msg == NULL)
+ if (!tlv_msg)
return NULL;
pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_SSID].value);
@@ -140,7 +140,7 @@ static uint8_t *encode_to_tlv(const char *ssid, const char *psk, int *length)
pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_AUTHENTICATION_TYPE].value);
pos += set_2b_into_tlv(tlv_msg+pos,
DEs[DE_AUTHENTICATION_TYPE].length);
- if (psk != NULL) {
+ if (psk) {
pos += set_2b_into_tlv(tlv_msg+pos, DE_VAL_PSK);
pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_NETWORK_KEY].value);
pos += set_2b_into_tlv(tlv_msg+pos, psk_len);
@@ -172,7 +172,7 @@ static int parse_request_oob_params(DBusMessage *message,
const char *key;
int arg_type;
- if (tlv_msg == NULL || length == NULL)
+ if (!tlv_msg || !length)
return -EINVAL;
dbus_message_iter_init(message, &iter);
@@ -225,15 +225,15 @@ static DBusMessage *create_request_oob_reply(DBusMessage *message)
uint8_t *tlv_msg;
int length;
- if (connman_technology_get_wifi_tethering(&ssid, &psk) == FALSE)
+ if (!connman_technology_get_wifi_tethering(&ssid, &psk))
return get_reply_on_error(message, ENOTSUP);
tlv_msg = encode_to_tlv(ssid, psk, &length);
- if (tlv_msg == NULL)
+ if (!tlv_msg)
return get_reply_on_error(message, ENOTSUP);
reply = dbus_message_new_method_return(message);
- if (reply == NULL)
+ if (!reply)
goto out;
dbus_message_iter_init_append(reply, &iter);
@@ -268,7 +268,7 @@ static DBusMessage *request_oob_method(DBusConnection *dbus_conn,
static void free_wifi_sc(struct wifi_sc *wsc)
{
- if (wsc == NULL)
+ if (!wsc)
return;
g_free(wsc->ssid);
@@ -289,7 +289,7 @@ static uint8_t *get_byte_array_from_tlv(const uint8_t *tlv_msg, int length)
uint8_t *array;
array = g_try_malloc0(sizeof(uint8_t) * length);
- if (array == NULL)
+ if (!array)
return NULL;
memcpy((void *)array, (void *)tlv_msg, length*sizeof(uint8_t));
@@ -302,7 +302,7 @@ static char *get_string_from_tlv(const uint8_t *tlv_msg, int length)
char *str;
str = g_try_malloc0((sizeof(char) * length) + 1);
- if (str == NULL)
+ if (!str)
return NULL;
memcpy((void *)str, (void *)tlv_msg, length*sizeof(char));
@@ -322,9 +322,9 @@ static inline DEid get_de_id(uint16_t attr)
return DE_MAX;
}
-static inline gboolean is_de_length_fine(DEid id, uint16_t length)
+static inline bool is_de_length_fine(DEid id, uint16_t length)
{
- if (DEs[id].fixed_length == TRUE)
+ if (DEs[id].fixed_length)
return (length == DEs[id].length);
return (length <= DEs[id].length);
@@ -336,7 +336,7 @@ static char *get_hexstr_from_byte_array(const uint8_t *bt, int length)
int i, j;
hex_str = g_try_malloc0(((length*2)+1) * sizeof(char));
- if (hex_str == NULL)
+ if (!hex_str)
return NULL;
for (i = 0, j = 0; i < length; i++, j += 2)
@@ -353,11 +353,11 @@ static struct wifi_sc *decode_from_tlv(const uint8_t *tlv_msg, int length)
int pos;
DEid id;
- if (tlv_msg == NULL || length == 0)
+ if (!tlv_msg || length == 0)
return NULL;
wsc = g_try_malloc0(sizeof(struct wifi_sc));
- if (wsc == NULL)
+ if (!wsc)
return NULL;
pos = 0;
@@ -374,7 +374,7 @@ static struct wifi_sc *decode_from_tlv(const uint8_t *tlv_msg, int length)
continue;
}
- if (is_de_length_fine(id, len) == FALSE)
+ if (!is_de_length_fine(id, len))
goto error;
switch (id) {
@@ -413,14 +413,14 @@ static int handle_wcs_data(const uint8_t *tlv_msg, int length)
int ret = -EINVAL;
wsc = decode_from_tlv(tlv_msg, length);
- if (wsc == NULL)
+ if (!wsc)
return -EINVAL;
- if (wsc->ssid == NULL)
+ if (!wsc->ssid)
goto out;
keyfile = g_key_file_new();
- if (keyfile == NULL) {
+ if (!keyfile) {
ret = -ENOMEM;
goto out;
}
@@ -432,7 +432,7 @@ static int handle_wcs_data(const uint8_t *tlv_msg, int length)
g_key_file_set_boolean(keyfile, NEARD_SERVICE_GROUP,
SERVICE_KEY_HIDDEN, TRUE);
- if (wsc->passphrase != NULL)
+ if (wsc->passphrase)
g_key_file_set_string(keyfile, NEARD_SERVICE_GROUP,
SERVICE_KEY_PASSPHRASE, wsc->passphrase);
@@ -468,7 +468,7 @@ static DBusMessage *release_method(DBusConnection *dbus_conn,
{
DBG("");
- agent_registered = FALSE;
+ agent_registered = false;
g_dbus_unregister_interface(connection,
AGENT_PATH, NEARD_AGENT_INTERFACE);
@@ -476,7 +476,7 @@ static DBusMessage *release_method(DBusConnection *dbus_conn,
}
static const GDBusMethodTable neard_methods[] = {
-{ GDBUS_ASYNC_METHOD("RequestOOB",
+ { GDBUS_ASYNC_METHOD("RequestOOB",
GDBUS_ARGS({ "data", "a{sv}" }),
GDBUS_ARGS({ "data", "a{sv}" }), request_oob_method) },
{ GDBUS_ASYNC_METHOD("PushOOB",
@@ -487,7 +487,7 @@ static const GDBusMethodTable neard_methods[] = {
static void cleanup_register_call(void)
{
- if (register_call != NULL) {
+ if (register_call) {
dbus_pending_call_cancel(register_call);
dbus_pending_call_unref(register_call);
register_call = NULL;
@@ -498,20 +498,20 @@ static void register_agent_cb(DBusPendingCall *pending, void *user_data)
{
DBusMessage *reply;
- if (dbus_pending_call_get_completed(pending) == FALSE)
+ if (!dbus_pending_call_get_completed(pending))
return;
register_call = NULL;
reply = dbus_pending_call_steal_reply(pending);
- if (reply == NULL)
+ if (!reply)
goto out;
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_unregister_interface(connection,
AGENT_PATH, NEARD_AGENT_INTERFACE);
} else
- agent_registered = TRUE;
+ agent_registered = true;
dbus_message_unref(reply);
out:
@@ -527,20 +527,20 @@ static void register_agent(void)
message = dbus_message_new_method_call(NEARD_SERVICE, NEARD_PATH,
NEARD_MANAGER_INTERFACE,
"RegisterHandoverAgent");
- if (message == NULL)
+ if (!message)
return;
dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH,
&path, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, message,
- &register_call, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &register_call, TIMEOUT)) {
dbus_message_unref(message);
goto out;
}
- if (dbus_pending_call_set_notify(register_call, register_agent_cb,
- NULL, NULL) == FALSE)
+ if (!dbus_pending_call_set_notify(register_call,
+ register_agent_cb, NULL, NULL))
cleanup_register_call();
out:
@@ -553,15 +553,15 @@ static void unregister_agent(void)
const char *type = AGENT_TYPE;
DBusMessage *message;
- if (agent_registered == FALSE)
+ if (!agent_registered)
return cleanup_register_call();
- agent_registered = FALSE;
+ agent_registered = false;
message = dbus_message_new_method_call(NEARD_SERVICE, NEARD_PATH,
NEARD_MANAGER_INTERFACE,
"UnregisterHandoverAgent");
- if (message != NULL) {
+ if (message) {
dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH,
&path, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID);
g_dbus_send_message(connection, message);
@@ -575,12 +575,12 @@ static void neard_is_present(DBusConnection *conn, void *user_data)
{
DBG("");
- if (agent_registered == TRUE)
+ if (agent_registered)
return;
if (g_dbus_register_interface(connection, AGENT_PATH,
NEARD_AGENT_INTERFACE, neard_methods,
- NULL, NULL, NULL, NULL) == TRUE)
+ NULL, NULL, NULL, NULL))
register_agent();
}
@@ -588,10 +588,10 @@ static void neard_is_out(DBusConnection *conn, void *user_data)
{
DBG("");
- if (agent_registered == TRUE) {
+ if (agent_registered) {
g_dbus_unregister_interface(connection,
AGENT_PATH, NEARD_AGENT_INTERFACE);
- agent_registered = FALSE;
+ agent_registered = false;
}
cleanup_register_call();
@@ -600,7 +600,7 @@ static void neard_is_out(DBusConnection *conn, void *user_data)
static int neard_init(void)
{
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
watch_id = g_dbus_add_service_watch(connection, NEARD_SERVICE,
@@ -620,7 +620,7 @@ static void neard_exit(void)
if (watch_id != 0)
g_dbus_remove_watch(connection, watch_id);
- if (connection != NULL)
+ if (connection)
dbus_connection_unref(connection);
}
diff --git a/plugins/nmcompat.c b/plugins/nmcompat.c
index 400389b3..883ce9bd 100644
--- a/plugins/nmcompat.c
+++ b/plugins/nmcompat.c
@@ -60,7 +60,7 @@ static void state_changed(dbus_uint32_t state)
signal = dbus_message_new_signal(NM_PATH, NM_INTERFACE,
"StateChanged");
- if (signal == NULL)
+ if (!signal)
return;
dbus_message_append_args(signal, DBUS_TYPE_UINT32, &state,
@@ -79,7 +79,7 @@ static void properties_changed(dbus_uint32_t state)
signal = dbus_message_new_signal(NM_PATH, NM_INTERFACE,
"PropertiesChanged");
- if (signal == NULL)
+ if (!signal)
return;
dbus_message_iter_init_append(signal, &iter);
@@ -112,7 +112,7 @@ static void default_changed(struct connman_service *service)
{
DBG("service %p", service);
- if (service == NULL)
+ if (!service)
nm_state = NM_STATE_DISCONNECTED;
else
nm_state = NM_STATE_CONNECTED_LOCAL;
@@ -128,7 +128,7 @@ static void service_state_changed(struct connman_service *service,
{
DBG("service %p state %d", service, state);
- if (current_service == NULL || current_service != service)
+ if (!current_service || current_service != service)
return;
switch (state) {
@@ -158,11 +158,11 @@ static void service_state_changed(struct connman_service *service,
properties_changed(nm_state);
}
-static void offline_mode(connman_bool_t enabled)
+static void offline_mode(bool enabled)
{
DBG("enabled %d", enabled);
- if (enabled == TRUE)
+ if (enabled)
nm_state = NM_STATE_ASLEEP;
else
nm_state = NM_STATE_DISCONNECTED;
@@ -191,18 +191,18 @@ static DBusMessage *property_get(DBusConnection *conn,
DBG("interface %s property %s", interface, key);
- if (g_str_equal(interface, NM_INTERFACE) == FALSE)
+ if (!g_str_equal(interface, NM_INTERFACE))
return dbus_message_new_error(msg, DBUS_ERROR_FAILED,
"Unsupported interface");
- if (g_str_equal(key, "State") == TRUE) {
+ if (g_str_equal(key, "State")) {
DBusMessage *reply;
DBusMessageIter iter, value;
DBG("state %d", nm_state);
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &iter);
@@ -240,10 +240,10 @@ static int nmcompat_init(void)
DBG("");
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -1;
- if (g_dbus_request_name(connection, NM_SERVICE, NULL) == FALSE) {
+ if (!g_dbus_request_name(connection, NM_SERVICE, NULL)) {
connman_error("nmcompat: failed to register service");
return -1;
}
@@ -253,9 +253,9 @@ static int nmcompat_init(void)
return -1;
}
- if (g_dbus_register_interface(connection, NM_PATH,
- DBUS_PROPERTIES_INTERFACE,
- methods, signals, NULL, NULL, NULL) == FALSE) {
+ if (!g_dbus_register_interface(connection, NM_PATH,
+ DBUS_PROPERTIES_INTERFACE, methods,
+ signals, NULL, NULL, NULL)) {
connman_error("nmcompat: failed to register "
DBUS_PROPERTIES_INTERFACE);
return -1;
@@ -270,7 +270,7 @@ static void nmcompat_exit(void)
connman_notifier_unregister(&notifier);
- if (connection == NULL)
+ if (!connection)
return;
g_dbus_unregister_interface(connection, NM_PATH,
diff --git a/plugins/ofono.c b/plugins/ofono.c
index 847f2562..fecef9cf 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -2,7 +2,7 @@
*
* Connection Manager
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2011 BWM Car IT GmbH. All rights reserved.
*
@@ -153,24 +153,23 @@ struct modem_data {
/* Modem Interface */
char *serial;
- connman_bool_t powered;
- connman_bool_t online;
+ bool powered;
+ bool online;
uint8_t interfaces;
- connman_bool_t ignore;
+ bool ignore;
- connman_bool_t set_powered;
+ bool set_powered;
/* CDMA ConnectionManager Interface */
- connman_bool_t cdma_cm_powered;
+ bool cdma_cm_powered;
/* ConnectionManager Interface */
- connman_bool_t attached;
- connman_bool_t cm_powered;
+ bool attached;
+ bool cm_powered;
/* ConnectionContext Interface */
- connman_bool_t active;
- connman_bool_t set_active;
- connman_bool_t valid_apn; /* APN is 'valid' if length > 0 */
+ bool active;
+ bool valid_apn; /* APN is 'valid' if length > 0 */
/* SimManager Interface */
char *imsi;
@@ -179,8 +178,8 @@ struct modem_data {
char *name;
uint8_t strength;
uint8_t data_strength; /* 1xEVDO signal strength */
- connman_bool_t registered;
- connman_bool_t roaming;
+ bool registered;
+ bool roaming;
/* pending calls */
DBusPendingCall *call_set_property;
@@ -214,7 +213,7 @@ static char *get_ident(const char *path)
return NULL;
pos = strrchr(path, '/');
- if (pos == NULL)
+ if (!pos)
return NULL;
return pos + 1;
@@ -225,7 +224,7 @@ static struct network_context *network_context_alloc(const char *path)
struct network_context *context;
context = g_try_new0(struct network_context, 1);
- if (context == NULL)
+ if (!context)
return NULL;
context->path = g_strdup(path);
@@ -258,7 +257,7 @@ static void network_context_free(struct network_context *context)
static void set_connected(struct modem_data *modem)
{
struct connman_service *service;
- connman_bool_t setip = FALSE;
+ bool setip = false;
enum connman_ipconfig_method method;
char *nameservers;
int index;
@@ -267,25 +266,25 @@ static void set_connected(struct modem_data *modem)
index = modem->context->index;
- if (index < 0 || modem->context->ipv4_address == NULL) {
+ method = modem->context->ipv4_method;
+ if (index < 0 || (!modem->context->ipv4_address &&
+ method == CONNMAN_IPCONFIG_METHOD_FIXED)) {
connman_error("Invalid index and/or address");
return;
}
service = connman_service_lookup_from_network(modem->network);
- if (service == NULL)
+ if (!service)
return;
- method = modem->context->ipv4_method;
if (method == CONNMAN_IPCONFIG_METHOD_FIXED ||
- method == CONNMAN_IPCONFIG_METHOD_DHCP)
- {
+ method == CONNMAN_IPCONFIG_METHOD_DHCP) {
connman_service_create_ip4config(service, index);
connman_network_set_index(modem->network, index);
connman_network_set_ipv4_method(modem->network, method);
- setip = TRUE;
+ setip = true;
}
if (method == CONNMAN_IPCONFIG_METHOD_FIXED) {
@@ -299,41 +298,41 @@ static void set_connected(struct modem_data *modem)
connman_network_set_ipv6_method(modem->network, method);
connman_network_set_ipaddress(modem->network,
modem->context->ipv6_address);
- setip = TRUE;
+ setip = true;
}
/* Set the nameservers */
- if (modem->context->ipv4_nameservers != NULL &&
- modem->context->ipv6_nameservers != NULL) {
+ if (modem->context->ipv4_nameservers &&
+ modem->context->ipv6_nameservers) {
nameservers = g_strdup_printf("%s %s",
modem->context->ipv4_nameservers,
modem->context->ipv6_nameservers);
connman_network_set_nameservers(modem->network, nameservers);
g_free(nameservers);
- } else if (modem->context->ipv4_nameservers != NULL) {
+ } else if (modem->context->ipv4_nameservers) {
connman_network_set_nameservers(modem->network,
modem->context->ipv4_nameservers);
- } else if (modem->context->ipv6_nameservers != NULL) {
+ } else if (modem->context->ipv6_nameservers) {
connman_network_set_nameservers(modem->network,
modem->context->ipv6_nameservers);
}
- if (setip == TRUE)
- connman_network_set_connected(modem->network, TRUE);
+ if (setip)
+ connman_network_set_connected(modem->network, true);
}
static void set_disconnected(struct modem_data *modem)
{
DBG("%s", modem->path);
- if (modem->network == NULL)
+ if (!modem->network)
return;
- connman_network_set_connected(modem->network, FALSE);
+ connman_network_set_connected(modem->network, false);
}
typedef void (*set_property_cb)(struct modem_data *data,
- connman_bool_t success);
+ bool success);
typedef void (*get_properties_cb)(struct modem_data *data,
DBusMessageIter *dict);
@@ -351,7 +350,7 @@ static void set_property_reply(DBusPendingCall *call, void *user_data)
struct property_info *info = user_data;
DBusMessage *reply;
DBusError error;
- connman_bool_t success = TRUE;
+ bool success = true;
DBG("%s path %s %s.%s", info->modem->path,
info->path, info->interface, info->property);
@@ -367,10 +366,10 @@ static void set_property_reply(DBusPendingCall *call, void *user_data)
info->path, info->interface, info->property,
error.name, error.message);
dbus_error_free(&error);
- success = FALSE;
+ success = false;
}
- if (info->set_property_cb != NULL)
+ if (info->set_property_cb)
(*info->set_property_cb)(info->modem, success);
dbus_message_unref(reply);
@@ -389,7 +388,7 @@ static int set_property(struct modem_data *modem,
DBG("%s path %s %s.%s", modem->path, path, interface, property);
- if (modem->call_set_property != NULL) {
+ if (modem->call_set_property) {
DBG("Cancel pending SetProperty");
dbus_pending_call_cancel(modem->call_set_property);
@@ -398,28 +397,28 @@ static int set_property(struct modem_data *modem,
message = dbus_message_new_method_call(OFONO_SERVICE, path,
interface, SET_PROPERTY);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
connman_dbus_property_append_basic(&iter, property, type, value);
- if (dbus_connection_send_with_reply(connection, message,
- &modem->call_set_property, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &modem->call_set_property, TIMEOUT)) {
connman_error("Failed to change property: %s %s.%s",
path, interface, property);
dbus_message_unref(message);
return -EINVAL;
}
- if (modem->call_set_property == NULL) {
+ if (!modem->call_set_property) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
}
info = g_try_new0(struct property_info, 1);
- if (info == NULL) {
+ if (!info) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -462,7 +461,7 @@ static void get_properties_reply(DBusPendingCall *call, void *user_data)
goto done;
}
- if (dbus_message_iter_init(reply, &array) == FALSE)
+ if (!dbus_message_iter_init(reply, &array))
goto done;
if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
@@ -470,7 +469,7 @@ static void get_properties_reply(DBusPendingCall *call, void *user_data)
dbus_message_iter_recurse(&array, &dict);
- if (info->get_properties_cb != NULL)
+ if (info->get_properties_cb)
(*info->get_properties_cb)(info->modem, &dict);
done:
@@ -489,31 +488,31 @@ static int get_properties(const char *path, const char *interface,
DBG("%s path %s %s", modem->path, path, interface);
- if (modem->call_get_properties != NULL) {
+ if (modem->call_get_properties) {
connman_error("Pending GetProperties");
return -EBUSY;
}
message = dbus_message_new_method_call(OFONO_SERVICE, path,
interface, GET_PROPERTIES);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
- if (dbus_connection_send_with_reply(connection, message,
- &modem->call_get_properties, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &modem->call_get_properties, TIMEOUT)) {
connman_error("Failed to call %s.GetProperties()", interface);
dbus_message_unref(message);
return -EINVAL;
}
- if (modem->call_get_properties == NULL) {
+ if (!modem->call_get_properties) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
}
info = g_try_new0(struct property_info, 1);
- if (info == NULL) {
+ if (!info) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -532,11 +531,11 @@ static int get_properties(const char *path, const char *interface,
}
static void context_set_active_reply(struct modem_data *modem,
- connman_bool_t success)
+ bool success)
{
DBG("%s", modem->path);
- if (success == TRUE) {
+ if (success) {
/*
* Don't handle do anything on success here. oFono will send
* the change via PropertyChanged singal.
@@ -551,7 +550,7 @@ static void context_set_active_reply(struct modem_data *modem,
* cycle the modem in such cases?
*/
- if (modem->network == NULL) {
+ if (!modem->network) {
/*
* In the case where we power down the device
* we don't wait for the reply, therefore the network
@@ -565,7 +564,7 @@ static void context_set_active_reply(struct modem_data *modem,
}
static int context_set_active(struct modem_data *modem,
- connman_bool_t active)
+ dbus_bool_t active)
{
int err;
@@ -577,18 +576,18 @@ static int context_set_active(struct modem_data *modem,
&active,
context_set_active_reply);
- if (active == FALSE && err == -EINPROGRESS)
+ if (!active && err == -EINPROGRESS)
return 0;
return err;
}
static void cdma_cm_set_powered_reply(struct modem_data *modem,
- connman_bool_t success)
+ bool success)
{
DBG("%s", modem->path);
- if (success == TRUE) {
+ if (success) {
/*
* Don't handle do anything on success here. oFono will send
* the change via PropertyChanged singal.
@@ -603,7 +602,7 @@ static void cdma_cm_set_powered_reply(struct modem_data *modem,
* cycle the modem in such cases?
*/
- if (modem->network == NULL) {
+ if (!modem->network) {
/*
* In the case where we power down the device
* we don't wait for the reply, therefore the network
@@ -616,7 +615,7 @@ static void cdma_cm_set_powered_reply(struct modem_data *modem,
CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
}
-static int cdma_cm_set_powered(struct modem_data *modem, connman_bool_t powered)
+static int cdma_cm_set_powered(struct modem_data *modem, dbus_bool_t powered)
{
int err;
@@ -627,13 +626,13 @@ static int cdma_cm_set_powered(struct modem_data *modem, connman_bool_t powered)
&powered,
cdma_cm_set_powered_reply);
- if (powered == FALSE && err == -EINPROGRESS)
+ if (!powered && err == -EINPROGRESS)
return 0;
return err;
}
-static int modem_set_online(struct modem_data *modem, connman_bool_t online)
+static int modem_set_online(struct modem_data *modem, dbus_bool_t online)
{
DBG("%s online %d", modem->path, online);
@@ -644,7 +643,7 @@ static int modem_set_online(struct modem_data *modem, connman_bool_t online)
NULL);
}
-static int cm_set_powered(struct modem_data *modem, connman_bool_t powered)
+static int cm_set_powered(struct modem_data *modem, dbus_bool_t powered)
{
int err;
@@ -656,13 +655,13 @@ static int cm_set_powered(struct modem_data *modem, connman_bool_t powered)
&powered,
NULL);
- if (powered == FALSE && err == -EINPROGRESS)
+ if (!powered && err == -EINPROGRESS)
return 0;
return err;
}
-static int modem_set_powered(struct modem_data *modem, connman_bool_t powered)
+static int modem_set_powered(struct modem_data *modem, dbus_bool_t powered)
{
int err;
@@ -676,19 +675,19 @@ static int modem_set_powered(struct modem_data *modem, connman_bool_t powered)
&powered,
NULL);
- if (powered == FALSE && err == -EINPROGRESS)
+ if (!powered && err == -EINPROGRESS)
return 0;
return err;
}
-static connman_bool_t has_interface(uint8_t interfaces,
+static bool has_interface(uint8_t interfaces,
enum ofono_api api)
{
if ((interfaces & api) == api)
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
static uint8_t extract_interfaces(DBusMessageIter *array)
@@ -703,15 +702,15 @@ static uint8_t extract_interfaces(DBusMessageIter *array)
dbus_message_iter_get_basic(&entry, &name);
- if (g_str_equal(name, OFONO_SIM_INTERFACE) == TRUE)
+ if (g_str_equal(name, OFONO_SIM_INTERFACE))
interfaces |= OFONO_API_SIM;
- else if (g_str_equal(name, OFONO_NETREG_INTERFACE) == TRUE)
+ else if (g_str_equal(name, OFONO_NETREG_INTERFACE))
interfaces |= OFONO_API_NETREG;
- else if (g_str_equal(name, OFONO_CM_INTERFACE) == TRUE)
+ else if (g_str_equal(name, OFONO_CM_INTERFACE))
interfaces |= OFONO_API_CM;
- else if (g_str_equal(name, OFONO_CDMA_CM_INTERFACE) == TRUE)
+ else if (g_str_equal(name, OFONO_CDMA_CM_INTERFACE))
interfaces |= OFONO_API_CDMA_CM;
- else if (g_str_equal(name, OFONO_CDMA_NETREG_INTERFACE) == TRUE)
+ else if (g_str_equal(name, OFONO_CDMA_NETREG_INTERFACE))
interfaces |= OFONO_API_CDMA_NETREG;
dbus_message_iter_next(&entry);
@@ -733,7 +732,7 @@ static char *extract_nameservers(DBusMessageIter *array)
dbus_message_iter_get_basic(&entry, &nameserver);
- if (nameservers == NULL) {
+ if (!nameservers) {
nameservers = g_strdup(nameserver);
} else {
tmp = nameservers;
@@ -771,7 +770,7 @@ static void extract_ipv4_settings(DBusMessageIter *array,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Interface") == TRUE) {
+ if (g_str_equal(key, "Interface")) {
dbus_message_iter_get_basic(&value, &interface);
DBG("Interface %s", interface);
@@ -779,34 +778,33 @@ static void extract_ipv4_settings(DBusMessageIter *array,
index = connman_inet_ifindex(interface);
DBG("index %d", index);
- } else if (g_str_equal(key, "Method") == TRUE) {
+ } else if (g_str_equal(key, "Method")) {
dbus_message_iter_get_basic(&value, &val);
DBG("Method %s", val);
- if (g_strcmp0(val, "static") == 0) {
+ if (g_strcmp0(val, "static") == 0)
context->ipv4_method = CONNMAN_IPCONFIG_METHOD_FIXED;
- } else if (g_strcmp0(val, "dhcp") == 0) {
+ else if (g_strcmp0(val, "dhcp") == 0)
context->ipv4_method = CONNMAN_IPCONFIG_METHOD_DHCP;
- break;
- }
- } else if (g_str_equal(key, "Address") == TRUE) {
+
+ } else if (g_str_equal(key, "Address")) {
dbus_message_iter_get_basic(&value, &val);
address = g_strdup(val);
DBG("Address %s", address);
- } else if (g_str_equal(key, "Netmask") == TRUE) {
+ } else if (g_str_equal(key, "Netmask")) {
dbus_message_iter_get_basic(&value, &val);
netmask = g_strdup(val);
DBG("Netmask %s", netmask);
- } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
+ } else if (g_str_equal(key, "DomainNameServers")) {
nameservers = extract_nameservers(&value);
DBG("Nameservers %s", nameservers);
- } else if (g_str_equal(key, "Gateway") == TRUE) {
+ } else if (g_str_equal(key, "Gateway")) {
dbus_message_iter_get_basic(&value, &val);
gateway = g_strdup(val);
@@ -820,17 +818,21 @@ static void extract_ipv4_settings(DBusMessageIter *array,
if (index < 0)
goto out;
+ context->index = index;
+
if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_FIXED)
goto out;
context->ipv4_address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
- if (context->ipv4_address == NULL)
+ if (!context->ipv4_address) {
+ context->index = -1;
goto out;
+ }
- context->index = index;
connman_ipaddress_set_ipv4(context->ipv4_address, address,
netmask, gateway);
+ g_free(context->ipv4_nameservers);
context->ipv4_nameservers = nameservers;
out:
@@ -867,7 +869,7 @@ static void extract_ipv6_settings(DBusMessageIter *array,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Interface") == TRUE) {
+ if (g_str_equal(key, "Interface")) {
dbus_message_iter_get_basic(&value, &interface);
DBG("Interface %s", interface);
@@ -875,21 +877,21 @@ static void extract_ipv6_settings(DBusMessageIter *array,
index = connman_inet_ifindex(interface);
DBG("index %d", index);
- } else if (g_str_equal(key, "Address") == TRUE) {
+ } else if (g_str_equal(key, "Address")) {
dbus_message_iter_get_basic(&value, &val);
address = g_strdup(val);
DBG("Address %s", address);
- } else if (g_str_equal(key, "PrefixLength") == TRUE) {
+ } else if (g_str_equal(key, "PrefixLength")) {
dbus_message_iter_get_basic(&value, &prefix_length);
DBG("prefix length %d", prefix_length);
- } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
+ } else if (g_str_equal(key, "DomainNameServers")) {
nameservers = extract_nameservers(&value);
DBG("Nameservers %s", nameservers);
- } else if (g_str_equal(key, "Gateway") == TRUE) {
+ } else if (g_str_equal(key, "Gateway")) {
dbus_message_iter_get_basic(&value, &val);
gateway = g_strdup(val);
@@ -907,13 +909,14 @@ static void extract_ipv6_settings(DBusMessageIter *array,
context->ipv6_address =
connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV6);
- if (context->ipv6_address == NULL)
+ if (!context->ipv6_address)
goto out;
context->index = index;
connman_ipaddress_set_ipv6(context->ipv6_address, address,
prefix_length, gateway);
+ g_free(context->ipv6_nameservers);
context->ipv6_nameservers = nameservers;
out:
@@ -924,7 +927,7 @@ out:
g_free(gateway);
}
-static connman_bool_t ready_to_create_device(struct modem_data *modem)
+static bool ready_to_create_device(struct modem_data *modem)
{
/*
* There are three different modem types which behave slightly
@@ -938,13 +941,13 @@ static connman_bool_t ready_to_create_device(struct modem_data *modem)
* before we are able to create a device.
*/
- if (modem->device != NULL)
- return FALSE;
+ if (modem->device)
+ return false;
- if (modem->imsi != NULL || modem->serial != NULL)
- return TRUE;
+ if (modem->imsi || modem->serial)
+ return true;
- return FALSE;
+ return false;
}
static void create_device(struct modem_data *modem)
@@ -954,18 +957,18 @@ static void create_device(struct modem_data *modem)
DBG("%s", modem->path);
- if (modem->imsi != NULL)
+ if (modem->imsi)
ident = modem->imsi;
- else if (modem->serial != NULL)
+ else if (modem->serial)
ident = modem->serial;
- if (connman_dbus_validate_ident(ident) == FALSE)
+ if (!connman_dbus_validate_ident(ident))
ident = connman_dbus_encode_string(ident);
else
ident = g_strdup(ident);
device = connman_device_create("ofono", CONNMAN_DEVICE_TYPE_CELLULAR);
- if (device == NULL)
+ if (!device)
goto out;
DBG("device %p", device);
@@ -993,9 +996,9 @@ static void destroy_device(struct modem_data *modem)
{
DBG("%s", modem->path);
- connman_device_set_powered(modem->device, FALSE);
+ connman_device_set_powered(modem->device, false);
- if (modem->network != NULL) {
+ if (modem->network) {
connman_device_remove_network(modem->device, modem->network);
connman_network_unref(modem->network);
modem->network = NULL;
@@ -1013,12 +1016,12 @@ static void add_network(struct modem_data *modem)
DBG("%s", modem->path);
- if (modem->network != NULL)
+ if (modem->network)
return;
modem->network = connman_network_create(modem->context->path,
CONNMAN_NETWORK_TYPE_CELLULAR);
- if (modem->network == NULL)
+ if (!modem->network)
return;
DBG("network %p", modem->network);
@@ -1028,7 +1031,7 @@ static void add_network(struct modem_data *modem)
connman_network_set_string(modem->network, "Path",
modem->context->path);
- if (modem->name != NULL)
+ if (modem->name)
connman_network_set_name(modem->network, modem->name);
else
connman_network_set_name(modem->network, "");
@@ -1052,7 +1055,7 @@ static void remove_network(struct modem_data *modem)
{
DBG("%s", modem->path);
- if (modem->network == NULL)
+ if (!modem->network)
return;
DBG("network %p", modem->network);
@@ -1067,11 +1070,11 @@ static int add_cm_context(struct modem_data *modem, const char *context_path,
{
const char *context_type = NULL;
struct network_context *context = NULL;
- connman_bool_t active = FALSE;
+ dbus_bool_t active = FALSE;
DBG("%s context path %s", modem->path, context_path);
- if (modem->context != NULL) {
+ if (modem->context) {
/*
* We have already assigned a context to this modem
* and we do only support one Internet context.
@@ -1080,7 +1083,7 @@ static int add_cm_context(struct modem_data *modem, const char *context_path,
}
context = network_context_alloc(context_path);
- if (context == NULL)
+ if (!context)
return -ENOMEM;
while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
@@ -1093,31 +1096,31 @@ static int add_cm_context(struct modem_data *modem, const char *context_path,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Type") == TRUE) {
+ if (g_str_equal(key, "Type")) {
dbus_message_iter_get_basic(&value, &context_type);
DBG("%s context %s type %s", modem->path,
context_path, context_type);
- } else if (g_str_equal(key, "Settings") == TRUE) {
+ } else if (g_str_equal(key, "Settings")) {
DBG("%s Settings", modem->path);
extract_ipv4_settings(&value, context);
- } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
+ } else if (g_str_equal(key, "IPv6.Settings")) {
DBG("%s IPv6.Settings", modem->path);
extract_ipv6_settings(&value, context);
- } else if (g_str_equal(key, "Active") == TRUE) {
+ } else if (g_str_equal(key, "Active")) {
dbus_message_iter_get_basic(&value, &active);
DBG("%s Active %d", modem->path, active);
- } else if (g_str_equal(key, "AccessPointName") == TRUE) {
+ } else if (g_str_equal(key, "AccessPointName")) {
const char *apn;
dbus_message_iter_get_basic(&value, &apn);
- if (apn != NULL && strlen(apn) > 0)
- modem->valid_apn = TRUE;
+ if (apn && strlen(apn) > 0)
+ modem->valid_apn = true;
else
- modem->valid_apn = FALSE;
+ modem->valid_apn = false;
DBG("%s AccessPointName '%s'", modem->path, apn);
}
@@ -1134,9 +1137,9 @@ static int add_cm_context(struct modem_data *modem, const char *context_path,
g_hash_table_replace(context_hash, g_strdup(context_path), modem);
- if (modem->valid_apn == TRUE && modem->attached == TRUE &&
+ if (modem->valid_apn && modem->attached &&
has_interface(modem->interfaces,
- OFONO_API_NETREG) == TRUE) {
+ OFONO_API_NETREG)) {
add_network(modem);
}
@@ -1146,10 +1149,10 @@ static int add_cm_context(struct modem_data *modem, const char *context_path,
static void remove_cm_context(struct modem_data *modem,
const char *context_path)
{
- if (modem->context == NULL)
+ if (!modem->context)
return;
- if (modem->network != NULL)
+ if (modem->network)
remove_network(modem);
g_hash_table_remove(context_hash, context_path);
@@ -1157,9 +1160,9 @@ static void remove_cm_context(struct modem_data *modem,
network_context_free(modem->context);
modem->context = NULL;
- modem->valid_apn = FALSE;
+ modem->valid_apn = false;
- if (modem->network != NULL)
+ if (modem->network)
remove_network(modem);
}
@@ -1175,10 +1178,10 @@ static gboolean context_changed(DBusConnection *conn,
DBG("context_path %s", context_path);
modem = g_hash_table_lookup(context_hash, context_path);
- if (modem == NULL)
+ if (!modem)
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);
@@ -1191,52 +1194,54 @@ static gboolean context_changed(DBusConnection *conn,
* Active. Settings will always be send before Active = True.
* That means we don't have to order here.
*/
- if (g_str_equal(key, "Settings") == TRUE) {
+ if (g_str_equal(key, "Settings")) {
DBG("%s Settings", modem->path);
extract_ipv4_settings(&value, modem->context);
- } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
+ } else if (g_str_equal(key, "IPv6.Settings")) {
DBG("%s IPv6.Settings", modem->path);
extract_ipv6_settings(&value, modem->context);
- } else if (g_str_equal(key, "Active") == TRUE) {
- dbus_message_iter_get_basic(&value, &modem->active);
+ } else if (g_str_equal(key, "Active")) {
+ dbus_bool_t active;
+
+ dbus_message_iter_get_basic(&value, &active);
+ modem->active = active;
DBG("%s Active %d", modem->path, modem->active);
- if (modem->active == TRUE)
+ if (modem->active)
set_connected(modem);
else
set_disconnected(modem);
- } else if (g_str_equal(key, "AccessPointName") == TRUE) {
+ } else if (g_str_equal(key, "AccessPointName")) {
const char *apn;
dbus_message_iter_get_basic(&value, &apn);
DBG("%s AccessPointName %s", modem->path, apn);
- if (apn != NULL && strlen(apn) > 0) {
- modem->valid_apn = TRUE;
+ if (apn && strlen(apn) > 0) {
+ modem->valid_apn = true;
- if (modem->network != NULL)
+ if (modem->network)
return TRUE;
- if (modem->attached == FALSE)
+ if (!modem->attached)
return TRUE;
- if (has_interface(modem->interfaces,
- OFONO_API_NETREG) == FALSE) {
+ if (!has_interface(modem->interfaces,
+ OFONO_API_NETREG))
return TRUE;
- }
add_network(modem);
- if (modem->active == TRUE)
+ if (modem->active)
set_connected(modem);
} else {
- modem->valid_apn = FALSE;
+ modem->valid_apn = false;
- if (modem->network == NULL)
+ if (!modem->network)
return TRUE;
remove_network(modem);
@@ -1261,13 +1266,13 @@ static void cm_get_contexts_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);
goto done;
}
- if (dbus_message_iter_init(reply, &array) == FALSE)
+ if (!dbus_message_iter_init(reply, &array))
goto done;
if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
@@ -1302,22 +1307,22 @@ static int cm_get_contexts(struct modem_data *modem)
DBG("%s", modem->path);
- if (modem->call_get_contexts != NULL)
+ if (modem->call_get_contexts)
return -EBUSY;
message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
OFONO_CM_INTERFACE, GET_CONTEXTS);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
- if (dbus_connection_send_with_reply(connection, message,
- &modem->call_get_contexts, TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &modem->call_get_contexts, TIMEOUT)) {
connman_error("Failed to call GetContexts()");
dbus_message_unref(message);
return -EINVAL;
}
- if (modem->call_get_contexts == NULL) {
+ if (!modem->call_get_contexts) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
@@ -1344,10 +1349,10 @@ static gboolean cm_context_added(DBusConnection *conn,
DBG("%s", path);
modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
+ if (!modem)
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, &context_path);
@@ -1372,13 +1377,13 @@ static gboolean cm_context_removed(DBusConnection *conn,
DBG("context 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, &context_path);
modem = g_hash_table_lookup(context_hash, context_path);
- if (modem == NULL)
+ if (!modem)
return TRUE;
remove_cm_context(modem, context_path);
@@ -1398,7 +1403,7 @@ static void netreg_update_name(struct modem_data *modem,
g_free(modem->name);
modem->name = g_strdup(name);
- if (modem->network == NULL)
+ if (!modem->network)
return;
connman_network_set_name(modem->network, modem->name);
@@ -1412,7 +1417,7 @@ static void netreg_update_strength(struct modem_data *modem,
DBG("%s Strength %d", modem->path, modem->strength);
- if (modem->network == NULL)
+ if (!modem->network)
return;
/*
@@ -1443,7 +1448,7 @@ static void netreg_update_datastrength(struct modem_data *modem,
DBG("%s Data Strength %d", modem->path, modem->data_strength);
- if (modem->network == NULL)
+ if (!modem->network)
return;
/*
@@ -1462,7 +1467,7 @@ static void netreg_update_status(struct modem_data *modem,
DBusMessageIter *value)
{
char *status;
- connman_bool_t roaming;
+ bool roaming;
dbus_message_iter_get_basic(value, &status);
@@ -1474,7 +1479,7 @@ static void netreg_update_status(struct modem_data *modem,
modem->roaming = roaming;
- if (modem->network == NULL)
+ if (!modem->network)
return;
connman_network_set_bool(modem->network,
@@ -1499,7 +1504,7 @@ static void netreg_update_regdom(struct modem_data *modem,
return;
alpha2 = mcc_country_codes[mcc - 200];
- if (alpha2 != NULL)
+ if (alpha2)
connman_technology_set_regdom(alpha2);
}
@@ -1512,13 +1517,13 @@ static gboolean netreg_changed(DBusConnection *conn, DBusMessage *message,
const char *key;
modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
+ if (!modem)
return TRUE;
- if (modem->ignore == TRUE)
+ if (modem->ignore)
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);
@@ -1526,13 +1531,13 @@ static gboolean netreg_changed(DBusConnection *conn, DBusMessage *message,
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
- if (g_str_equal(key, "Name") == TRUE)
+ if (g_str_equal(key, "Name"))
netreg_update_name(modem, &value);
- else if (g_str_equal(key, "Strength") == TRUE)
+ else if (g_str_equal(key, "Strength"))
netreg_update_strength(modem, &value);
- else if (g_str_equal(key, "Status") == TRUE)
+ else if (g_str_equal(key, "Status"))
netreg_update_status(modem, &value);
- else if (g_str_equal(key, "MobileCountryCode") == TRUE)
+ else if (g_str_equal(key, "MobileCountryCode"))
netreg_update_regdom(modem, &value);
return TRUE;
@@ -1553,19 +1558,19 @@ static void netreg_properties_reply(struct modem_data *modem,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Name") == TRUE)
+ if (g_str_equal(key, "Name"))
netreg_update_name(modem, &value);
- else if (g_str_equal(key, "Strength") == TRUE)
+ else if (g_str_equal(key, "Strength"))
netreg_update_strength(modem, &value);
- else if (g_str_equal(key, "Status") == TRUE)
+ else if (g_str_equal(key, "Status"))
netreg_update_status(modem, &value);
- else if (g_str_equal(key, "MobileCountryCode") == TRUE)
+ else if (g_str_equal(key, "MobileCountryCode"))
netreg_update_regdom(modem, &value);
dbus_message_iter_next(dict);
}
- if (modem->context == NULL) {
+ if (!modem->context) {
/*
* netgreg_get_properties() was issued after we got
* cm_get_contexts_reply() where we create the
@@ -1577,10 +1582,10 @@ static void netreg_properties_reply(struct modem_data *modem,
return;
}
- if (modem->valid_apn == TRUE)
+ if (modem->valid_apn)
add_network(modem);
- if (modem->active == TRUE)
+ if (modem->active)
set_connected(modem);
}
@@ -1593,22 +1598,22 @@ static int netreg_get_properties(struct modem_data *modem)
static void add_cdma_network(struct modem_data *modem)
{
/* Be sure that device is created before adding CDMA network */
- if (modem->device == NULL)
+ if (!modem->device)
return;
/*
* CDMA modems don't need contexts for data call, however the current
* add_network() logic needs one, so we create one to proceed.
*/
- if (modem->context == NULL)
+ if (!modem->context)
modem->context = network_context_alloc(modem->path);
- if (modem->name == NULL)
+ if (!modem->name)
modem->name = g_strdup("CDMA Network");
add_network(modem);
- if (modem->cdma_cm_powered == TRUE)
+ if (modem->cdma_cm_powered)
set_connected(modem);
}
@@ -1624,13 +1629,13 @@ static gboolean cdma_netreg_changed(DBusConnection *conn,
DBG("");
modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
+ if (!modem)
return TRUE;
- if (modem->ignore == TRUE)
+ if (modem->ignore)
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);
@@ -1638,16 +1643,16 @@ static gboolean cdma_netreg_changed(DBusConnection *conn,
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
- if (g_str_equal(key, "Name") == TRUE)
+ if (g_str_equal(key, "Name"))
netreg_update_name(modem, &value);
- else if (g_str_equal(key, "Strength") == TRUE)
+ else if (g_str_equal(key, "Strength"))
netreg_update_strength(modem, &value);
- else if (g_str_equal(key, "DataStrength") == TRUE)
+ else if (g_str_equal(key, "DataStrength"))
netreg_update_datastrength(modem, &value);
- else if (g_str_equal(key, "Status") == TRUE)
+ else if (g_str_equal(key, "Status"))
netreg_update_status(modem, &value);
- if (modem->registered == TRUE)
+ if (modem->registered)
add_cdma_network(modem);
else
remove_network(modem);
@@ -1670,19 +1675,19 @@ static void cdma_netreg_properties_reply(struct modem_data *modem,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Name") == TRUE)
+ if (g_str_equal(key, "Name"))
netreg_update_name(modem, &value);
- else if (g_str_equal(key, "Strength") == TRUE)
+ else if (g_str_equal(key, "Strength"))
netreg_update_strength(modem, &value);
- else if (g_str_equal(key, "DataStrength") == TRUE)
+ else if (g_str_equal(key, "DataStrength"))
netreg_update_datastrength(modem, &value);
- else if (g_str_equal(key, "Status") == TRUE)
+ else if (g_str_equal(key, "Status"))
netreg_update_status(modem, &value);
dbus_message_iter_next(dict);
}
- if (modem->registered == TRUE)
+ if (modem->registered)
add_cdma_network(modem);
else
remove_network(modem);
@@ -1697,19 +1702,20 @@ static int cdma_netreg_get_properties(struct modem_data *modem)
static void cm_update_attached(struct modem_data *modem,
DBusMessageIter *value)
{
- dbus_message_iter_get_basic(value, &modem->attached);
+ dbus_bool_t attached;
+
+ dbus_message_iter_get_basic(value, &attached);
+ modem->attached = attached;
DBG("%s Attached %d", modem->path, modem->attached);
- if (modem->attached == FALSE) {
+ if (!modem->attached) {
remove_network(modem);
return;
}
- if (has_interface(modem->interfaces,
- OFONO_API_NETREG) == FALSE) {
+ if (!has_interface(modem->interfaces, OFONO_API_NETREG))
return;
- }
netreg_get_properties(modem);
}
@@ -1717,12 +1723,15 @@ static void cm_update_attached(struct modem_data *modem,
static void cm_update_powered(struct modem_data *modem,
DBusMessageIter *value)
{
- dbus_message_iter_get_basic(value, &modem->cm_powered);
+ dbus_bool_t cm_powered;
+
+ dbus_message_iter_get_basic(value, &cm_powered);
+ modem->cm_powered = cm_powered;
DBG("%s ConnnectionManager Powered %d", modem->path,
modem->cm_powered);
- if (modem->cm_powered == TRUE)
+ if (modem->cm_powered)
return;
cm_set_powered(modem, TRUE);
@@ -1737,13 +1746,13 @@ static gboolean cm_changed(DBusConnection *conn, DBusMessage *message,
const char *key;
modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
+ if (!modem)
return TRUE;
- if (modem->ignore == TRUE)
+ if (modem->ignore)
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);
@@ -1751,9 +1760,9 @@ static gboolean cm_changed(DBusConnection *conn, DBusMessage *message,
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
- if (g_str_equal(key, "Attached") == TRUE)
+ if (g_str_equal(key, "Attached"))
cm_update_attached(modem, &value);
- else if (g_str_equal(key, "Powered") == TRUE)
+ else if (g_str_equal(key, "Powered"))
cm_update_powered(modem, &value);
return TRUE;
@@ -1762,14 +1771,17 @@ static gboolean cm_changed(DBusConnection *conn, DBusMessage *message,
static void cdma_cm_update_powered(struct modem_data *modem,
DBusMessageIter *value)
{
- dbus_message_iter_get_basic(value, &modem->cdma_cm_powered);
+ dbus_bool_t cdma_cm_powered;
+
+ dbus_message_iter_get_basic(value, &cdma_cm_powered);
+ modem->cdma_cm_powered = cdma_cm_powered;
DBG("%s CDMA cm Powered %d", modem->path, modem->cdma_cm_powered);
- if (modem->network == NULL)
+ if (!modem->network)
return;
- if (modem->cdma_cm_powered == TRUE)
+ if (modem->cdma_cm_powered)
set_connected(modem);
else
set_disconnected(modem);
@@ -1792,13 +1804,13 @@ static gboolean cdma_cm_changed(DBusConnection *conn,
const char *key;
modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
+ if (!modem)
return TRUE;
- if (modem->online == TRUE && modem->network == NULL)
+ if (modem->online && !modem->network)
cdma_netreg_get_properties(modem);
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &key);
@@ -1806,9 +1818,9 @@ static gboolean cdma_cm_changed(DBusConnection *conn,
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
- if (g_str_equal(key, "Powered") == TRUE)
+ if (g_str_equal(key, "Powered"))
cdma_cm_update_powered(modem, &value);
- if (g_str_equal(key, "Settings") == TRUE)
+ if (g_str_equal(key, "Settings"))
cdma_cm_update_settings(modem, &value);
return TRUE;
@@ -1828,9 +1840,9 @@ static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Attached") == TRUE)
+ if (g_str_equal(key, "Attached"))
cm_update_attached(modem, &value);
- else if (g_str_equal(key, "Powered") == TRUE)
+ else if (g_str_equal(key, "Powered"))
cm_update_powered(modem, &value);
dbus_message_iter_next(dict);
@@ -1848,7 +1860,7 @@ static void cdma_cm_properties_reply(struct modem_data *modem,
{
DBG("%s", modem->path);
- if (modem->online == TRUE)
+ if (modem->online)
cdma_netreg_get_properties(modem);
while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
@@ -1861,9 +1873,9 @@ static void cdma_cm_properties_reply(struct modem_data *modem,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Powered") == TRUE)
+ if (g_str_equal(key, "Powered"))
cdma_cm_update_powered(modem, &value);
- if (g_str_equal(key, "Settings") == TRUE)
+ if (g_str_equal(key, "Settings"))
cdma_cm_update_settings(modem, &value);
dbus_message_iter_next(dict);
@@ -1877,7 +1889,7 @@ static int cdma_cm_get_properties(struct modem_data *modem)
}
static void sim_update_imsi(struct modem_data *modem,
- DBusMessageIter* value)
+ DBusMessageIter *value)
{
char *imsi;
@@ -1898,13 +1910,13 @@ static gboolean sim_changed(DBusConnection *conn, DBusMessage *message,
const char *key;
modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
+ if (!modem)
return TRUE;
- if (modem->ignore == TRUE)
+ if (modem->ignore)
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);
@@ -1912,10 +1924,10 @@ static gboolean sim_changed(DBusConnection *conn, DBusMessage *message,
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
- if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
+ if (g_str_equal(key, "SubscriberIdentity")) {
sim_update_imsi(modem, &value);
- if (ready_to_create_device(modem) == FALSE)
+ if (!ready_to_create_device(modem))
return TRUE;
/*
@@ -1945,10 +1957,10 @@ static void sim_properties_reply(struct modem_data *modem,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
+ if (g_str_equal(key, "SubscriberIdentity")) {
sim_update_imsi(modem, &value);
- if (ready_to_create_device(modem) == FALSE)
+ if (!ready_to_create_device(modem))
return;
/*
@@ -1959,7 +1971,7 @@ static void sim_properties_reply(struct modem_data *modem,
*/
create_device(modem);
- if (modem->online == FALSE)
+ if (!modem->online)
return;
/*
@@ -1968,7 +1980,7 @@ static void sim_properties_reply(struct modem_data *modem,
* state machine will not go to next step. We have to
* trigger it from here.
*/
- if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
+ if (has_interface(modem->interfaces, OFONO_API_CM)) {
cm_get_properties(modem);
cm_get_contexts(modem);
}
@@ -1985,28 +1997,28 @@ static int sim_get_properties(struct modem_data *modem)
sim_properties_reply, modem);
}
-static connman_bool_t api_added(uint8_t old_iface, uint8_t new_iface,
+static bool api_added(uint8_t old_iface, uint8_t new_iface,
enum ofono_api api)
{
- if (has_interface(old_iface, api) == FALSE &&
- has_interface(new_iface, api) == TRUE) {
+ if (!has_interface(old_iface, api) &&
+ has_interface(new_iface, api)) {
DBG("%s added", api2string(api));
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
-static connman_bool_t api_removed(uint8_t old_iface, uint8_t new_iface,
+static bool api_removed(uint8_t old_iface, uint8_t new_iface,
enum ofono_api api)
{
- if (has_interface(old_iface, api) == TRUE &&
- has_interface(new_iface, api) == FALSE) {
+ if (has_interface(old_iface, api) &&
+ !has_interface(new_iface, api)) {
DBG("%s removed", api2string(api));
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
static void modem_update_interfaces(struct modem_data *modem,
@@ -2015,9 +2027,9 @@ static void modem_update_interfaces(struct modem_data *modem,
{
DBG("%s", modem->path);
- if (api_added(old_ifaces, new_ifaces, OFONO_API_SIM) == TRUE) {
- if (modem->imsi == NULL &&
- modem->set_powered == FALSE) {
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_SIM)) {
+ if (!modem->imsi &&
+ !modem->set_powered) {
/*
* Only use do GetProperties() when
* device has not been powered up.
@@ -2026,48 +2038,43 @@ static void modem_update_interfaces(struct modem_data *modem,
}
}
- if (api_added(old_ifaces, new_ifaces, OFONO_API_CM) == TRUE) {
- if (modem->device != NULL) {
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_CM)) {
+ if (modem->device) {
cm_get_properties(modem);
cm_get_contexts(modem);
}
}
- if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_CM) == TRUE) {
- if (ready_to_create_device(modem) == TRUE) {
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_CM)) {
+ if (ready_to_create_device(modem)) {
create_device(modem);
- if (modem->registered == TRUE)
+ if (modem->registered)
add_cdma_network(modem);
}
- if (modem->device != NULL)
+ if (modem->device)
cdma_cm_get_properties(modem);
}
- if (api_added(old_ifaces, new_ifaces, OFONO_API_NETREG) == TRUE) {
- if (modem->attached == TRUE)
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_NETREG)) {
+ if (modem->attached)
netreg_get_properties(modem);
}
- if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG) == TRUE) {
+ if (api_added(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG))
cdma_netreg_get_properties(modem);
- }
- if (api_removed(old_ifaces, new_ifaces, OFONO_API_CM) == TRUE) {
+ if (api_removed(old_ifaces, new_ifaces, OFONO_API_CM))
remove_cm_context(modem, modem->context->path);
- }
- if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_CM) == TRUE) {
+ if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_CM))
remove_cm_context(modem, modem->context->path);
- }
- if (api_removed(old_ifaces, new_ifaces, OFONO_API_NETREG) == TRUE) {
+ if (api_removed(old_ifaces, new_ifaces, OFONO_API_NETREG))
remove_network(modem);
- }
- if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG == TRUE)) {
+ if (api_removed(old_ifaces, new_ifaces, OFONO_API_CDMA_NETREG))
remove_network(modem);
- }
}
static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,
@@ -2079,13 +2086,13 @@ static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,
const char *key;
modem = g_hash_table_lookup(modem_hash, path);
- if (modem == NULL)
+ if (!modem)
return TRUE;
- if (modem->ignore == TRUE)
+ if (modem->ignore)
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);
@@ -2093,23 +2100,29 @@ static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &value);
- if (g_str_equal(key, "Powered") == TRUE) {
- dbus_message_iter_get_basic(&value, &modem->powered);
+ if (g_str_equal(key, "Powered")) {
+ dbus_bool_t powered;
+
+ dbus_message_iter_get_basic(&value, &powered);
+ modem->powered = powered;
DBG("%s Powered %d", modem->path, modem->powered);
- if (modem->powered == FALSE)
+ if (!modem->powered)
modem_set_powered(modem, TRUE);
- } else if (g_str_equal(key, "Online") == TRUE) {
- dbus_message_iter_get_basic(&value, &modem->online);
+ } else if (g_str_equal(key, "Online")) {
+ dbus_bool_t online;
+
+ dbus_message_iter_get_basic(&value, &online);
+ modem->online = online;
DBG("%s Online %d", modem->path, modem->online);
- if (modem->device == NULL)
+ if (!modem->device)
return TRUE;
connman_device_set_powered(modem->device, modem->online);
- } else if (g_str_equal(key, "Interfaces") == TRUE) {
+ } else if (g_str_equal(key, "Interfaces")) {
uint8_t interfaces;
interfaces = extract_interfaces(&value);
@@ -2122,7 +2135,7 @@ static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,
modem_update_interfaces(modem, modem->interfaces, interfaces);
modem->interfaces = interfaces;
- } else if (g_str_equal(key, "Serial") == TRUE) {
+ } else if (g_str_equal(key, "Serial")) {
char *serial;
dbus_message_iter_get_basic(&value, &serial);
@@ -2133,10 +2146,10 @@ static gboolean modem_changed(DBusConnection *conn, DBusMessage *message,
DBG("%s Serial %s", modem->path, modem->serial);
if (has_interface(modem->interfaces,
- OFONO_API_CDMA_CM) == TRUE) {
- if (ready_to_create_device(modem) == TRUE) {
+ OFONO_API_CDMA_CM)) {
+ if (ready_to_create_device(modem)) {
create_device(modem);
- if (modem->registered == TRUE)
+ if (modem->registered)
add_cdma_network(modem);
}
}
@@ -2152,7 +2165,7 @@ static void add_modem(const char *path, DBusMessageIter *prop)
DBG("%s", path);
modem = g_hash_table_lookup(modem_hash, path);
- if (modem != NULL) {
+ if (modem) {
/*
* When oFono powers up we ask for the modems and oFono is
* reporting with modem_added signal the modems. Only
@@ -2162,7 +2175,7 @@ static void add_modem(const char *path, DBusMessageIter *prop)
}
modem = g_try_new0(struct modem_data, 1);
- if (modem == NULL)
+ if (!modem)
return;
modem->path = g_strdup(path);
@@ -2179,27 +2192,33 @@ static void add_modem(const char *path, DBusMessageIter *prop)
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Powered") == TRUE) {
- dbus_message_iter_get_basic(&value, &modem->powered);
+ if (g_str_equal(key, "Powered")) {
+ dbus_bool_t powered;
+
+ dbus_message_iter_get_basic(&value, &powered);
+ modem->powered = powered;
DBG("%s Powered %d", modem->path, modem->powered);
- } else if (g_str_equal(key, "Online") == TRUE) {
- dbus_message_iter_get_basic(&value, &modem->online);
+ } else if (g_str_equal(key, "Online")) {
+ dbus_bool_t online;
+
+ dbus_message_iter_get_basic(&value, &online);
+ modem->online = online;
DBG("%s Online %d", modem->path, modem->online);
- } else if (g_str_equal(key, "Interfaces") == TRUE) {
+ } else if (g_str_equal(key, "Interfaces")) {
modem->interfaces = extract_interfaces(&value);
DBG("%s Interfaces 0x%02x", modem->path,
modem->interfaces);
- } else if (g_str_equal(key, "Serial") == TRUE) {
+ } else if (g_str_equal(key, "Serial")) {
char *serial;
dbus_message_iter_get_basic(&value, &serial);
modem->serial = g_strdup(serial);
DBG("%s Serial %s", modem->path, modem->serial);
- } else if (g_str_equal(key, "Type") == TRUE) {
+ } else if (g_str_equal(key, "Type")) {
char *type;
dbus_message_iter_get_basic(&value, &type);
@@ -2207,17 +2226,17 @@ static void add_modem(const char *path, DBusMessageIter *prop)
DBG("%s Type %s", modem->path, type);
if (g_strcmp0(type, "hardware") != 0) {
DBG("%s Ignore this modem", modem->path);
- modem->ignore = TRUE;
+ modem->ignore = true;
}
}
dbus_message_iter_next(prop);
}
- if (modem->ignore == TRUE)
+ if (modem->ignore)
return;
- if (modem->powered == FALSE) {
+ if (!modem->powered) {
modem_set_powered(modem, TRUE);
return;
}
@@ -2231,7 +2250,7 @@ static void modem_power_down(gpointer key, gpointer value, gpointer user_data)
DBG("%s", modem->path);
- if (modem->ignore == TRUE)
+ if (modem->ignore)
return;
modem_set_powered(modem, FALSE);
@@ -2243,19 +2262,19 @@ static void remove_modem(gpointer data)
DBG("%s", modem->path);
- if (modem->call_set_property != NULL)
+ if (modem->call_set_property)
dbus_pending_call_cancel(modem->call_set_property);
- if (modem->call_get_properties != NULL)
+ if (modem->call_get_properties)
dbus_pending_call_cancel(modem->call_get_properties);
- if (modem->call_get_contexts != NULL)
+ if (modem->call_get_contexts)
dbus_pending_call_cancel(modem->call_get_contexts);
- if (modem->device != NULL)
+ if (modem->device)
destroy_device(modem);
- if (modem->context != NULL)
+ if (modem->context)
remove_cm_context(modem, modem->context->path);
g_free(modem->serial);
@@ -2274,7 +2293,7 @@ static gboolean modem_added(DBusConnection *conn,
DBG("");
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &path);
@@ -2295,7 +2314,7 @@ static gboolean modem_removed(DBusConnection *conn,
DBG("");
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &path);
@@ -2317,13 +2336,13 @@ static void manager_get_modems_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);
goto done;
}
- if (dbus_message_iter_init(reply, &array) == FALSE)
+ if (!dbus_message_iter_init(reply, &array))
goto done;
dbus_message_iter_recurse(&array, &dict);
@@ -2358,17 +2377,17 @@ static int manager_get_modems(void)
message = dbus_message_new_method_call(OFONO_SERVICE, "/",
OFONO_MANAGER_INTERFACE, GET_MODEMS);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
- 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 call GetModems()");
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
connman_error("D-Bus connection not available");
dbus_message_unref(message);
return -EINVAL;
@@ -2388,12 +2407,12 @@ static void ofono_connect(DBusConnection *conn, void *user_data)
modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, remove_modem);
- if (modem_hash == NULL)
+ if (!modem_hash)
return;
context_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, NULL);
- if (context_hash == NULL) {
+ if (!context_hash) {
g_hash_table_destroy(modem_hash);
return;
}
@@ -2405,7 +2424,7 @@ static void ofono_disconnect(DBusConnection *conn, void *user_data)
{
DBG("");
- if (modem_hash == NULL || context_hash == NULL)
+ if (!modem_hash || !context_hash)
return;
g_hash_table_destroy(modem_hash);
@@ -2437,9 +2456,9 @@ static int network_connect(struct connman_network *network)
DBG("%s network %p", modem->path, network);
- if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE)
+ if (has_interface(modem->interfaces, OFONO_API_CM))
return context_set_active(modem, TRUE);
- else if (has_interface(modem->interfaces, OFONO_API_CDMA_CM) == TRUE)
+ else if (has_interface(modem->interfaces, OFONO_API_CDMA_CM))
return cdma_cm_set_powered(modem, TRUE);
connman_error("Connection manager interface not available");
@@ -2453,9 +2472,9 @@ static int network_disconnect(struct connman_network *network)
DBG("%s network %p", modem->path, network);
- if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE)
+ if (has_interface(modem->interfaces, OFONO_API_CM))
return context_set_active(modem, FALSE);
- else if (has_interface(modem->interfaces, OFONO_API_CDMA_CM) == TRUE)
+ else if (has_interface(modem->interfaces, OFONO_API_CDMA_CM))
return cdma_cm_set_powered(modem, FALSE);
connman_error("Connection manager interface not available");
@@ -2494,7 +2513,7 @@ static int modem_enable(struct connman_device *device)
DBG("%s device %p", modem->path, device);
- if (modem->online == TRUE)
+ if (modem->online)
return 0;
return modem_set_online(modem, TRUE);
@@ -2506,7 +2525,7 @@ static int modem_disable(struct connman_device *device)
DBG("%s device %p", modem->path, device);
- if (modem->online == FALSE)
+ if (!modem->online)
return 0;
return modem_set_online(modem, FALSE);
@@ -2557,7 +2576,7 @@ static int ofono_init(void)
DBG("");
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
watch = g_dbus_add_service_watch(connection,
@@ -2685,7 +2704,7 @@ static void ofono_exit(void)
{
DBG("");
- if (modem_hash != NULL) {
+ if (modem_hash) {
/*
* We should propably wait for the SetProperty() reply
* message, because ...
@@ -2699,7 +2718,7 @@ static void ofono_exit(void)
modem_hash = NULL;
}
- if (context_hash != NULL) {
+ if (context_hash) {
g_hash_table_destroy(context_hash);
context_hash = NULL;
}
diff --git a/plugins/pacrunner.c b/plugins/pacrunner.c
index 418dce20..850139fd 100644
--- a/plugins/pacrunner.c
+++ b/plugins/pacrunner.c
@@ -2,7 +2,7 @@
*
* 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
@@ -67,8 +67,8 @@ static void create_config_reply(DBusPendingCall *call, void *user_data)
goto done;
}
- if (dbus_message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID) == FALSE)
+ if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH,
+ &path, DBUS_TYPE_INVALID))
goto done;
g_free(current_config);
@@ -88,7 +88,7 @@ static void append_string_list(DBusMessageIter *iter, void *user_data)
char **list = user_data;
int i;
- for (i = 0; list[i] != NULL; i++)
+ for (i = 0; list[i]; i++)
dbus_message_iter_append_basic(iter,
DBUS_TYPE_STRING, &list[i]);
}
@@ -104,14 +104,14 @@ static void create_proxy_configuration(void)
const char *str;
char **str_list;
- if (default_service == NULL)
+ if (!default_service)
return;
DBG("");
msg = dbus_message_new_method_call(PACRUNNER_SERVICE, PACRUNNER_PATH,
PACRUNNER_INTERFACE, "CreateProxyConfiguration");
- if (msg == NULL)
+ if (!msg)
return;
dbus_message_set_auto_start(msg, FALSE);
@@ -130,7 +130,7 @@ static void create_proxy_configuration(void)
method = "manual";
str_list = connman_service_get_proxy_servers(default_service);
- if (str_list == NULL) {
+ if (!str_list) {
connman_dbus_dict_close(&iter, &dict);
goto done;
}
@@ -141,7 +141,7 @@ static void create_proxy_configuration(void)
g_strfreev(str_list);
str_list = connman_service_get_proxy_excludes(default_service);
- if (str_list == NULL)
+ if (!str_list)
break;
connman_dbus_dict_append_array(&dict, "Excludes",
@@ -154,10 +154,10 @@ static void create_proxy_configuration(void)
method = "auto";
str = connman_service_get_proxy_url(default_service);
- if (str == NULL) {
+ if (!str) {
str = connman_service_get_proxy_autoconfig(
default_service);
- if (str == NULL) {
+ if (!str) {
connman_dbus_dict_close(&iter, &dict);
goto done;
}
@@ -172,19 +172,19 @@ static void create_proxy_configuration(void)
DBUS_TYPE_STRING, &method);
interface = connman_service_get_interface(default_service);
- if (interface != NULL) {
+ if (interface) {
connman_dbus_dict_append_basic(&dict, "Interface",
DBUS_TYPE_STRING, &interface);
g_free(interface);
}
str = connman_service_get_domainname(default_service);
- if (str != NULL)
+ if (str)
connman_dbus_dict_append_array(&dict, "Domains",
DBUS_TYPE_STRING, append_string, &str);
str_list = connman_service_get_nameservers(default_service);
- if (str_list != NULL)
+ if (str_list)
connman_dbus_dict_append_array(&dict, "Nameservers",
DBUS_TYPE_STRING, append_string_list,
str_list);
@@ -195,7 +195,7 @@ static void create_proxy_configuration(void)
result = dbus_connection_send_with_reply(connection, msg,
&call, DBUS_TIMEOUT);
- if (result == FALSE || call == NULL)
+ if (!result || !call)
goto done;
dbus_pending_call_set_notify(call, create_config_reply, NULL, NULL);
@@ -224,14 +224,14 @@ static void destroy_proxy_configuration(void)
DBusPendingCall *call;
dbus_bool_t result;
- if (current_config == NULL)
+ if (!current_config)
return;
DBG("");
msg = dbus_message_new_method_call(PACRUNNER_SERVICE, PACRUNNER_PATH,
PACRUNNER_INTERFACE, "DestroyProxyConfiguration");
- if (msg == NULL)
+ if (!msg)
return;
dbus_message_set_auto_start(msg, FALSE);
@@ -244,7 +244,7 @@ static void destroy_proxy_configuration(void)
dbus_message_unref(msg);
- if (result == FALSE || call == NULL)
+ if (!result || !call)
return;
dbus_pending_call_set_notify(call, destroy_config_reply, NULL, NULL);
@@ -264,7 +264,7 @@ static void default_service_changed(struct connman_service *service)
default_service = service;
- if (daemon_running == FALSE)
+ if (!daemon_running)
return;
destroy_proxy_configuration();
@@ -279,7 +279,7 @@ static void proxy_changed(struct connman_service *service)
if (service != default_service)
return;
- if (daemon_running == FALSE)
+ if (!daemon_running)
return;
destroy_proxy_configuration();
@@ -317,18 +317,18 @@ static char * parse_url(const char *url)
char *scheme, *host, *path, *host_ret;
scheme = g_strdup(url);
- if (scheme == NULL)
+ if (!scheme)
return NULL;
host = strstr(scheme, "://");
- if (host != NULL) {
+ if (host) {
*host = '\0';
host += 3;
} else
host = scheme;
path = strchr(host, '/');
- if (path != NULL)
+ if (path)
*(path++) = '\0';
host_ret = g_strdup(host);
@@ -352,8 +352,8 @@ static void request_lookup_reply(DBusPendingCall *call, void *user_data)
goto done;
}
- if (dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &proxy,
- DBUS_TYPE_INVALID) == FALSE)
+ if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING,
+ &proxy, DBUS_TYPE_INVALID))
proxy = NULL;
done:
@@ -377,24 +377,21 @@ static int request_lookup(struct connman_service *service, const char *url)
DBG("");
- if (daemon_running == FALSE)
- return -EINVAL;
-
msg = dbus_message_new_method_call(PACRUNNER_SERVICE,
PACRUNNER_CLIENT_PATH,
PACRUNNER_CLIENT_INTERFACE,
"FindProxyForURL");
- if (msg == NULL)
+ if (!msg)
return -1;
host = parse_url(url);
- if (host == NULL) {
+ if (!host) {
dbus_message_unref(msg);
return -EINVAL;
}
data = g_try_new0(struct proxy_data, 1);
- if (data == NULL) {
+ if (!data) {
dbus_message_unref(msg);
g_free(host);
return -ENOMEM;
@@ -403,8 +400,6 @@ static int request_lookup(struct connman_service *service, const char *url)
data->url = g_strdup(url);
data->service = connman_service_ref(service);
- dbus_message_set_auto_start(msg, FALSE);
-
dbus_message_append_args(msg, DBUS_TYPE_STRING, &url,
DBUS_TYPE_STRING, &host,
DBUS_TYPE_INVALID);
@@ -414,7 +409,7 @@ static int request_lookup(struct connman_service *service, const char *url)
dbus_message_unref(msg);
- if (result == FALSE || call == NULL) {
+ if (!result || !call) {
g_free(host);
g_free(data->url);
g_free(data);
@@ -447,7 +442,7 @@ static guint pacrunner_watch;
static int pacrunner_init(void)
{
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
pacrunner_watch = g_dbus_add_service_watch(connection,
diff --git a/plugins/session_policy_local.c b/plugins/session_policy_local.c
index 8a25c3ce..4e8b5f21 100644
--- a/plugins/session_policy_local.c
+++ b/plugins/session_policy_local.c
@@ -42,6 +42,8 @@
#include <connman/dbus.h>
#include <connman/inotify.h>
+#include "src/shared/util.h"
+
#define POLICYDIR STORAGEDIR "/session_policy_local"
#define MODE (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \
@@ -168,11 +170,13 @@ static void finish_create(struct policy_config *policy,
connman_session_config_func_t cb,
void *user_data)
{
- struct policy_group *group;
+ struct policy_group *group = NULL;
GSList *list;
- group = g_hash_table_lookup(selinux_hash, policy->selinux);
- if (group != NULL) {
+ if (policy->selinux)
+ group = g_hash_table_lookup(selinux_hash, policy->selinux);
+
+ if (group) {
set_policy(policy, group);
policy->config->id_type = CONNMAN_SESSION_ID_TYPE_LSM;
@@ -180,8 +184,10 @@ static void finish_create(struct policy_config *policy,
goto done;
}
- group = g_hash_table_lookup(uid_hash, policy->uid);
- if (group != NULL) {
+ if (policy->uid)
+ group = g_hash_table_lookup(uid_hash, policy->uid);
+
+ if (group) {
set_policy(policy, group);
policy->config->id_type = CONNMAN_SESSION_ID_TYPE_UID;
@@ -189,11 +195,11 @@ static void finish_create(struct policy_config *policy,
goto done;
}
- for (list = policy->gids; list != NULL; list = list->next) {
+ for (list = policy->gids; list; list = list->next) {
char *gid = list->data;
group = g_hash_table_lookup(gid_hash, gid);
- if (group == NULL)
+ if (!group)
continue;
set_policy(policy, group);
@@ -227,8 +233,14 @@ static void selinux_context_reply(const unsigned char *context, void *user_data,
DBG("session %p", policy->session);
+ if (err == -EIO) {
+ /* No SELinux support, drop back to UID/GID only mode */
+ finish_create(policy, cb, cbd->user_data);
+ goto done;
+ }
+
if (err < 0) {
- failed_create(policy, cb, user_data, err);
+ failed_create(policy, cb, cbd->user_data, err);
goto done;
}
@@ -236,7 +248,7 @@ static void selinux_context_reply(const unsigned char *context, void *user_data,
policy->selinux_context = g_strdup((const char *)context);
ident = parse_selinux_type(policy->selinux_context);
- if (ident != NULL)
+ if (ident)
policy->selinux = g_strdup(ident);
finish_create(policy, cb, cbd->user_data);
@@ -265,7 +277,7 @@ static void get_uid_reply(unsigned int uid, void *user_data, int err)
}
pwd = getpwuid((uid_t)uid);
- if (pwd == NULL) {
+ if (!pwd) {
if (errno != 0)
err = -errno;
else
@@ -278,7 +290,7 @@ static void get_uid_reply(unsigned int uid, void *user_data, int err)
nrgroups = 0;
getgrouplist(pwd->pw_name, pwd->pw_gid, NULL, &nrgroups);
groups = g_try_new0(gid_t, nrgroups);
- if (groups == NULL) {
+ if (!groups) {
err = -ENOMEM;
goto err;
}
@@ -289,7 +301,7 @@ static void get_uid_reply(unsigned int uid, void *user_data, int err)
for (i = 0; i < nrgroups; i++) {
grp = getgrgid(groups[i]);
- if (grp == NULL) {
+ if (!grp) {
if (errno != 0)
err = -errno;
else
@@ -321,7 +333,7 @@ static void get_uid_reply(unsigned int uid, void *user_data, int err)
return;
err:
- failed_create(NULL, cb, user_data, err);
+ failed_create(NULL, cb, cbd->user_data, err);
g_free(cbd);
g_free(groups);
}
@@ -364,7 +376,7 @@ static void policy_local_destroy(struct connman_session *session)
DBG("session %p", session);
policy = g_hash_table_lookup(session_hash, session);
- if (policy == NULL)
+ if (!policy)
return;
g_hash_table_remove(session_hash, session);
@@ -384,7 +396,7 @@ static int load_keyfile(const char *pathname, GKeyFile **keyfile)
*keyfile = g_key_file_new();
- if (g_key_file_load_from_file(*keyfile, pathname, 0, &error) == FALSE)
+ if (!g_key_file_load_from_file(*keyfile, pathname, 0, &error))
goto err;
return 0;
@@ -421,7 +433,7 @@ static int load_policy(GKeyFile *keyfile, const char *groupname,
group->uid = g_key_file_get_string(keyfile, groupname,
"uid", NULL);
- if (group->selinux == NULL && group->gid == NULL && group->uid == NULL)
+ if (!group->selinux && !group->gid && !group->uid)
return -EINVAL;
config->priority = g_key_file_get_boolean(keyfile, groupname,
@@ -429,14 +441,14 @@ static int load_policy(GKeyFile *keyfile, const char *groupname,
str = g_key_file_get_string(keyfile, groupname, "RoamingPolicy",
NULL);
- if (str != NULL) {
+ if (str) {
config->roaming_policy = connman_session_parse_roaming_policy(str);
g_free(str);
}
str = g_key_file_get_string(keyfile, groupname, "ConnectionType",
NULL);
- if (str != NULL) {
+ if (str) {
config->type = connman_session_parse_connection_type(str);
g_free(str);
}
@@ -446,10 +458,10 @@ static int load_policy(GKeyFile *keyfile, const char *groupname,
str = g_key_file_get_string(keyfile, groupname, "AllowedBearers",
NULL);
- if (str != NULL) {
+ if (str) {
tokens = g_strsplit(str, " ", 0);
- for (i = 0; tokens[i] != NULL; i++) {
+ for (i = 0; tokens[i]; i++) {
err = connman_session_parse_bearers(tokens[i],
&config->allowed_bearers);
if (err < 0)
@@ -470,7 +482,7 @@ static void update_session(struct policy_config *policy)
{
DBG("policy %p session %p", policy, policy->session);
- if (policy->session == NULL)
+ if (!policy->session)
return;
if (connman_session_config_update(policy->session) < 0)
@@ -492,7 +504,7 @@ static void cleanup_config(gpointer user_data)
DBG("policy %p group %p", policy, policy->group);
- if (policy->group != NULL)
+ if (policy->group)
policy->group->sessions =
g_slist_remove(policy->group->sessions, policy);
@@ -517,11 +529,11 @@ static void cleanup_group(gpointer user_data)
g_slist_free(group->config->allowed_bearers);
g_free(group->config->id);
g_free(group->config);
- if (group->selinux != NULL)
+ if (group->selinux)
g_hash_table_remove(selinux_hash, group->selinux);
- if (group->uid != NULL)
+ if (group->uid)
g_hash_table_remove(uid_hash, group->uid);
- if (group->gid != NULL)
+ if (group->gid)
g_hash_table_remove(gid_hash, group->gid);
g_free(group->selinux);
g_free(group->uid);
@@ -547,14 +559,16 @@ static void recheck_sessions(void)
GSList *list;
g_hash_table_iter_init(&iter, session_hash);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
struct policy_config *policy = value;
- if (policy->group != NULL)
+ if (policy->group)
continue;
- group = g_hash_table_lookup(selinux_hash, policy->selinux);
- if (group != NULL) {
+ if (policy->selinux)
+ group = g_hash_table_lookup(selinux_hash,
+ policy->selinux);
+ if (group) {
policy->config->id_type = CONNMAN_SESSION_ID_TYPE_LSM;
g_free(policy->config->id);
policy->config->id = g_strdup(policy->selinux_context);
@@ -563,7 +577,7 @@ static void recheck_sessions(void)
}
group = g_hash_table_lookup(uid_hash, policy->uid);
- if (group != NULL) {
+ if (group) {
set_policy(policy, group);
policy->config->id_type = CONNMAN_SESSION_ID_TYPE_UID;
@@ -573,10 +587,10 @@ static void recheck_sessions(void)
continue;
}
- for (list = policy->gids; list != NULL; list = list->next) {
+ for (list = policy->gids; list; list = list->next) {
char *gid = list->data;
group = g_hash_table_lookup(gid_hash, gid);
- if (group != NULL) {
+ if (group) {
set_policy(policy, group);
policy->config->id_type = CONNMAN_SESSION_ID_TYPE_GID;
@@ -607,7 +621,7 @@ static int load_file(const char *filename, struct policy_file *file)
groupnames = g_key_file_get_groups(keyfile, NULL);
- for (i = 0; groupnames[i] != NULL; i++) {
+ for (i = 0; groupnames[i]; i++) {
group = g_new0(struct policy_group, 1);
group->config = g_new0(struct connman_session_config, 1);
@@ -617,13 +631,13 @@ static int load_file(const char *filename, struct policy_file *file)
g_free(group);
break;
}
- if (group->selinux != NULL)
+ if (group->selinux)
g_hash_table_replace(selinux_hash, group->selinux, group);
- if (group->uid != NULL)
+ if (group->uid)
g_hash_table_replace(uid_hash, group->uid, group);
- if (group->gid != NULL)
+ if (group->gid)
g_hash_table_replace(gid_hash, group->gid, group);
file->groups = g_slist_prepend(file->groups, group);
@@ -639,18 +653,18 @@ static int load_file(const char *filename, struct policy_file *file)
return err;
}
-static connman_bool_t is_filename_valid(const char *filename)
+static bool is_filename_valid(const char *filename)
{
- if (filename == NULL)
- return FALSE;
+ if (!filename)
+ return false;
if (filename[0] == '.')
- return FALSE;
+ return false;
return g_str_has_suffix(filename, ".policy");
}
-static int read_policies()
+static int read_policies(void)
{
GDir *dir;
const gchar *filename;
@@ -659,11 +673,11 @@ static int read_policies()
DBG("");
dir = g_dir_open(POLICYDIR, 0, NULL);
- if (dir == NULL)
+ if (!dir)
return -EINVAL;
- while ((filename = g_dir_read_name(dir)) != NULL) {
- if (is_filename_valid(filename) == FALSE)
+ while ((filename = g_dir_read_name(dir))) {
+ if (!is_filename_valid(filename))
continue;
file = g_new0(struct policy_file, 1);
@@ -691,7 +705,7 @@ static void notify_handler(struct inotify_event *event,
if (event->mask & IN_CREATE)
return;
- if (is_filename_valid(filename) == FALSE)
+ if (!is_filename_valid(filename))
return;
/*
@@ -725,7 +739,7 @@ static int session_policy_local_init(void)
DBG("");
/* If the dir doesn't exist, create it */
- if (g_file_test(POLICYDIR, G_FILE_TEST_IS_DIR) == FALSE) {
+ if (!g_file_test(POLICYDIR, G_FILE_TEST_IS_DIR)) {
if (mkdir(POLICYDIR, MODE) < 0) {
if (errno != EEXIST)
return -errno;
@@ -733,7 +747,7 @@ static int session_policy_local_init(void)
}
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
file_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
@@ -764,19 +778,19 @@ err_notify:
connman_inotify_unregister(POLICYDIR, notify_handler);
err:
- if (file_hash != NULL)
+ if (file_hash)
g_hash_table_destroy(file_hash);
- if (session_hash != NULL)
+ if (session_hash)
g_hash_table_destroy(session_hash);
- if (selinux_hash != NULL)
+ if (selinux_hash)
g_hash_table_destroy(selinux_hash);
- if (uid_hash != NULL)
+ if (uid_hash)
g_hash_table_destroy(uid_hash);
- if (gid_hash != NULL)
+ if (gid_hash)
g_hash_table_destroy(gid_hash);
connman_session_policy_unregister(&session_policy_local);
diff --git a/plugins/tist.c b/plugins/tist.c
index 4d3561e4..ad5ef79e 100644
--- a/plugins/tist.c
+++ b/plugins/tist.c
@@ -25,6 +25,7 @@
#define _GNU_SOURCE
#include <stdio.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
@@ -105,7 +106,7 @@ static int read_baud_rate(unsigned long *baud)
DBG("");
f = fopen(TIST_SYSFS_BAUD, "r");
- if (f == NULL)
+ if (!f)
return -EIO;
err = fscanf(f, "%lu", baud);
@@ -126,7 +127,7 @@ static int read_uart_name(char uart_name[], size_t uart_name_len)
memset(uart_name, 0, uart_name_len);
f = fopen(TIST_SYSFS_UART, "r");
- if (f == NULL)
+ if (!f)
return -EIO;
err = fscanf(f, "%s", uart_name);
@@ -342,7 +343,7 @@ err:
return FALSE;
}
-static int install_ldisc(GIOChannel *channel, gboolean install)
+static int install_ldisc(GIOChannel *channel, bool install)
{
int uart_fd, err;
struct speed_change_cmd cmd;
@@ -350,11 +351,11 @@ static int install_ldisc(GIOChannel *channel, gboolean install)
DBG("%d %p", install, uart_channel);
- if (install == FALSE) {
+ if (!install) {
install_count = 0;
__sync_synchronize();
- if (uart_channel == NULL) {
+ if (!uart_channel) {
DBG("UART channel is NULL");
return 0;
}
@@ -367,19 +368,19 @@ static int install_ldisc(GIOChannel *channel, gboolean install)
return 0;
}
- if (uart_channel != NULL) {
+ if (uart_channel) {
g_io_channel_shutdown(uart_channel, TRUE, NULL);
g_io_channel_unref(uart_channel);
uart_channel = NULL;
}
DBG("opening %s custom baud %lu", uart_dev_name, baud_rate);
-
+
uart_fd = open(uart_dev_name, O_RDWR | O_CLOEXEC);
if (uart_fd < 0)
return -EIO;
- uart_channel = g_io_channel_unix_new(uart_fd);
+ uart_channel = g_io_channel_unix_new(uart_fd);
g_io_channel_set_close_on_unref(uart_channel, TRUE);
g_io_channel_set_encoding(uart_channel, NULL, NULL);
@@ -441,7 +442,7 @@ static gboolean install_event(GIOChannel *channel,
{
GIOStatus status = G_IO_STATUS_NORMAL;
unsigned int install_state;
- gboolean install;
+ bool install;
char buf[8];
gsize len;
@@ -462,7 +463,8 @@ static gboolean install_event(GIOChannel *channel,
}
/* Read the install value */
- status = g_io_channel_read_chars(channel, (gchar *) buf, 8, &len, NULL);
+ status = g_io_channel_read_chars(channel, (gchar *) buf,
+ 8, &len, NULL);
if (status != G_IO_STATUS_NORMAL) {
g_io_channel_shutdown(channel, TRUE, NULL);
g_io_channel_unref(channel);
@@ -575,7 +577,7 @@ static int tist_init(void)
install_count = 1;
__sync_synchronize();
- err = install_ldisc(install_channel, TRUE);
+ err = install_ldisc(install_channel, true);
if (err < 0) {
connman_error("ldisc installtion failed");
return err;
@@ -597,7 +599,7 @@ static void tist_exit(void)
g_io_channel_shutdown(install_channel, TRUE, NULL);
g_io_channel_unref(install_channel);
- if (uart_channel != NULL) {
+ if (uart_channel) {
g_io_channel_shutdown(uart_channel, TRUE, NULL);
g_io_channel_unref(uart_channel);
uart_channel = NULL;
diff --git a/plugins/vpn.c b/plugins/vpn.c
index 400112e7..25711d70 100644
--- a/plugins/vpn.c
+++ b/plugins/vpn.c
@@ -2,7 +2,7 @@
*
* Connection Manager
*
- * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012-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
@@ -71,7 +71,7 @@ struct connection_data {
struct connman_provider *provider;
int index;
DBusPendingCall *call;
- connman_bool_t connect_pending;
+ bool connect_pending;
struct config_create_data *cb_data;
char *state;
@@ -81,7 +81,7 @@ struct connection_data {
char **host_ip;
char *domain;
char **nameservers;
- gboolean immutable;
+ bool immutable;
GHashTable *server_routes;
GHashTable *user_routes;
@@ -99,22 +99,22 @@ static int set_string(struct connman_provider *provider,
struct connection_data *data;
data = connman_provider_get_data(provider);
- if (data == NULL)
+ if (!data)
return -EINVAL;
DBG("data %p provider %p key %s value %s", data, provider, key, value);
- if (g_str_equal(key, "Type") == TRUE) {
+ if (g_str_equal(key, "Type")) {
g_free(data->type);
data->type = g_strdup(value);
- } else if (g_str_equal(key, "Name") == TRUE) {
+ } else if (g_str_equal(key, "Name")) {
g_free(data->name);
data->name = g_strdup(value);
- } else if (g_str_equal(key, "Host") == TRUE) {
+ } else if (g_str_equal(key, "Host")) {
g_free(data->host);
data->host = g_strdup(value);
- } else if (g_str_equal(key, "VPN.Domain") == TRUE ||
- g_str_equal(key, "Domain") == TRUE) {
+ } else if (g_str_equal(key, "VPN.Domain") ||
+ g_str_equal(key, "Domain")) {
g_free(data->domain);
data->domain = g_strdup(value);
} else
@@ -129,24 +129,24 @@ static const char *get_string(struct connman_provider *provider,
struct connection_data *data;
data = connman_provider_get_data(provider);
- if (data == NULL)
+ if (!data)
return NULL;
DBG("data %p provider %p key %s", data, provider, key);
- if (g_str_equal(key, "Type") == TRUE)
+ if (g_str_equal(key, "Type"))
return data->type;
- else if (g_str_equal(key, "Name") == TRUE)
+ else if (g_str_equal(key, "Name"))
return data->name;
- else if (g_str_equal(key, "Host") == TRUE)
+ else if (g_str_equal(key, "Host"))
return data->host;
- else if (g_str_equal(key, "HostIP") == TRUE) {
- if (data->host_ip == NULL ||
- data->host_ip[0] == NULL)
+ else if (g_str_equal(key, "HostIP")) {
+ if (!data->host_ip ||
+ !data->host_ip[0])
return data->host;
else
return data->host_ip[0];
- } else if (g_str_equal(key, "VPN.Domain") == TRUE)
+ } else if (g_str_equal(key, "VPN.Domain"))
return data->domain;
return g_hash_table_lookup(data->setting_strings, key);
@@ -160,7 +160,7 @@ static char *get_ident(const char *path)
return NULL;
pos = strrchr(path, '/');
- if (pos == NULL)
+ if (!pos)
return NULL;
return pos + 1;
@@ -193,9 +193,11 @@ static void resolv_result(GResolvResultStatus status,
DBG("status %d", status);
- if (status == G_RESOLV_RESULT_STATUS_SUCCESS && results != NULL &&
- g_strv_length(results) > 0)
+ if (status == G_RESOLV_RESULT_STATUS_SUCCESS && results &&
+ g_strv_length(results) > 0) {
+ g_strfreev(data->host_ip);
data->host_ip = g_strdupv(results);
+ }
/*
* We cannot unref the resolver here as resolv struct is manipulated
@@ -208,17 +210,17 @@ static void resolv_result(GResolvResultStatus status,
static void resolv_host_addr(struct connection_data *data)
{
- if (data->host == NULL)
+ if (!data->host)
return;
if (connman_inet_check_ipaddress(data->host) > 0)
return;
- if (data->host_ip != NULL)
+ if (data->host_ip)
return;
data->resolv = g_resolv_new(0);
- if (data->resolv == NULL) {
+ if (!data->resolv) {
DBG("Cannot resolv %s", data->host);
return;
}
@@ -231,13 +233,13 @@ static void resolv_host_addr(struct connection_data *data)
static void free_config_cb_data(struct config_create_data *cb_data)
{
- if (cb_data == NULL)
+ if (!cb_data)
return;
g_free(cb_data->path);
cb_data->path = NULL;
- if (cb_data->message != NULL) {
+ if (cb_data->message) {
dbus_message_unref(cb_data->message);
cb_data->message = NULL;
}
@@ -254,18 +256,18 @@ static void set_provider_state(struct connection_data *data)
DBG("provider %p new state %s", data->provider, data->state);
- if (g_str_equal(data->state, "ready") == TRUE) {
+ if (g_str_equal(data->state, "ready")) {
state = CONNMAN_PROVIDER_STATE_READY;
goto set;
- } else if (g_str_equal(data->state, "configuration") == TRUE) {
+ } else if (g_str_equal(data->state, "configuration")) {
state = CONNMAN_PROVIDER_STATE_CONNECT;
- } else if (g_str_equal(data->state, "idle") == TRUE) {
+ } else if (g_str_equal(data->state, "idle")) {
state = CONNMAN_PROVIDER_STATE_IDLE;
- } else if (g_str_equal(data->state, "disconnect") == TRUE) {
+ } else if (g_str_equal(data->state, "disconnect")) {
err = ECONNREFUSED;
state = CONNMAN_PROVIDER_STATE_DISCONNECT;
goto set;
- } else if (g_str_equal(data->state, "failure") == TRUE) {
+ } else if (g_str_equal(data->state, "failure")) {
err = ECONNREFUSED;
state = CONNMAN_PROVIDER_STATE_FAILURE;
goto set;
@@ -275,7 +277,7 @@ static void set_provider_state(struct connection_data *data)
return;
set:
- if (data->cb_data != NULL)
+ if (data->cb_data)
data->cb_data->callback(data->cb_data->message,
err, data->ident);
@@ -293,7 +295,7 @@ static int create_provider(struct connection_data *data, void *user_data)
DBG("%s", data->path);
data->provider = connman_provider_get(data->ident);
- if (data->provider == NULL)
+ if (!data->provider)
return -ENOMEM;
DBG("provider %p name %s", data->provider, data->name);
@@ -304,10 +306,10 @@ static int create_provider(struct connection_data *data, void *user_data)
err = connman_provider_create_service(data->provider);
if (err == 0) {
connman_provider_set_immutable(data->provider, data->immutable);
- if (g_str_equal(data->state, "ready") == TRUE) {
+ if (g_str_equal(data->state, "ready")) {
connman_provider_set_index(data->provider,
data->index);
- if (data->ip != NULL)
+ if (data->ip)
connman_provider_set_ipaddress(data->provider,
data->ip);
}
@@ -333,7 +335,7 @@ static struct connection_data *create_connection_data(const char *path)
struct connection_data *data;
data = g_try_new0(struct connection_data, 1);
- if (data == NULL)
+ if (!data)
return NULL;
DBG("path %s", path);
@@ -375,19 +377,19 @@ static int extract_ip(DBusMessageIter *array, int family,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Address") == TRUE) {
+ if (g_str_equal(key, "Address")) {
dbus_message_iter_get_basic(&value, &address);
DBG("address %s", address);
- } else if (g_str_equal(key, "Netmask") == TRUE) {
+ } else if (g_str_equal(key, "Netmask")) {
dbus_message_iter_get_basic(&value, &netmask);
DBG("netmask %s", netmask);
- } else if (g_str_equal(key, "PrefixLength") == TRUE) {
+ } else if (g_str_equal(key, "PrefixLength")) {
dbus_message_iter_get_basic(&value, &netmask);
DBG("prefix length %s", netmask);
- } else if (g_str_equal(key, "Peer") == TRUE) {
+ } else if (g_str_equal(key, "Peer")) {
dbus_message_iter_get_basic(&value, &peer);
DBG("peer %s", peer);
- } else if (g_str_equal(key, "Gateway") == TRUE) {
+ } else if (g_str_equal(key, "Gateway")) {
dbus_message_iter_get_basic(&value, &gateway);
DBG("gateway %s", gateway);
}
@@ -397,7 +399,7 @@ static int extract_ip(DBusMessageIter *array, int family,
connman_ipaddress_free(data->ip);
data->ip = connman_ipaddress_alloc(family);
- if (data->ip == NULL)
+ if (!data->ip)
return -ENOMEM;
switch (family) {
@@ -434,13 +436,13 @@ static int extract_nameservers(DBusMessageIter *array,
dbus_message_iter_get_basic(&entry, &nameserver);
nameservers = g_try_renew(char *, nameservers, i + 2);
- if (nameservers == NULL)
+ if (!nameservers)
return -ENOMEM;
DBG("[%d] %s", i, nameserver);
nameservers[i] = g_strdup(nameserver);
- if (nameservers[i] == NULL)
+ if (!nameservers[i])
return -ENOMEM;
nameservers[++i] = NULL;
@@ -471,7 +473,7 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
struct connection_data *data = user_data;
struct config_create_data *cb_data = data->cb_data;
- if (dbus_pending_call_get_completed(call) == FALSE)
+ if (!dbus_pending_call_get_completed(call))
return;
DBG("user_data %p path %s", user_data, cb_data ? cb_data->path : NULL);
@@ -480,7 +482,7 @@ static void connect_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)) {
int err = errorstr2val(error.name);
if (err != -EINPROGRESS) {
connman_error("Connect reply: %s (%s)", error.message,
@@ -488,7 +490,7 @@ static void connect_reply(DBusPendingCall *call, void *user_data)
dbus_error_free(&error);
DBG("data %p cb_data %p", data, cb_data);
- if (cb_data != NULL) {
+ if (cb_data) {
cb_data->callback(cb_data->message, err, NULL);
free_config_cb_data(cb_data);
data->cb_data = NULL;
@@ -518,28 +520,28 @@ static int connect_provider(struct connection_data *data, void *user_data)
DBG("data %p user %p path %s", data, cb_data, data->path);
- data->connect_pending = FALSE;
+ data->connect_pending = false;
message = dbus_message_new_method_call(VPN_SERVICE, data->path,
VPN_CONNECTION_INTERFACE,
VPN_CONNECT);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
- if (dbus_connection_send_with_reply(connection, message,
- &call, DBUS_TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &call, DBUS_TIMEOUT)) {
connman_error("Unable to call %s.%s()",
VPN_CONNECTION_INTERFACE, VPN_CONNECT);
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
dbus_message_unref(message);
return -EINVAL;
}
- if (cb_data != NULL) {
+ if (cb_data) {
g_free(cb_data->path);
cb_data->path = g_strdup(data->path);
}
@@ -557,22 +559,22 @@ static void add_connection(const char *path, DBusMessageIter *properties,
struct connection_data *data;
int err;
char *ident = get_ident(path);
- connman_bool_t found = FALSE;
+ bool found = false;
data = g_hash_table_lookup(vpn_connections, ident);
- if (data != NULL) {
+ if (data) {
/*
* We might have a dummy connection struct here that
* was created by configuration_create_reply() so in
* that case just continue.
*/
- if (data->connect_pending == FALSE)
+ if (!data->connect_pending)
return;
- found = TRUE;
+ found = true;
} else {
data = create_connection_data(path);
- if (data == NULL)
+ if (!data)
return;
}
@@ -590,36 +592,39 @@ static void add_connection(const char *path, DBusMessageIter *properties,
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "State") == TRUE) {
+ if (g_str_equal(key, "State")) {
dbus_message_iter_get_basic(&value, &str);
DBG("state %s -> %s", data->state, str);
data->state = g_strdup(str);
- } else if (g_str_equal(key, "IPv4") == TRUE) {
+ } else if (g_str_equal(key, "IPv4")) {
extract_ip(&value, AF_INET, data);
- } else if (g_str_equal(key, "IPv6") == TRUE) {
+ } else if (g_str_equal(key, "IPv6")) {
extract_ip(&value, AF_INET6, data);
- } else if (g_str_equal(key, "Name") == TRUE) {
+ } else if (g_str_equal(key, "Name")) {
dbus_message_iter_get_basic(&value, &str);
data->name = g_strdup(str);
- } else if (g_str_equal(key, "Type") == TRUE) {
+ } else if (g_str_equal(key, "Type")) {
dbus_message_iter_get_basic(&value, &str);
data->type = g_strdup(str);
- } else if (g_str_equal(key, "Immutable") == TRUE) {
- dbus_message_iter_get_basic(&value, &data->immutable);
- } else if (g_str_equal(key, "Host") == TRUE) {
+ } else if (g_str_equal(key, "Immutable")) {
+ dbus_bool_t immutable;
+
+ dbus_message_iter_get_basic(&value, &immutable);
+ data->immutable = immutable;
+ } else if (g_str_equal(key, "Host")) {
dbus_message_iter_get_basic(&value, &str);
data->host = g_strdup(str);
- } else if (g_str_equal(key, "Domain") == TRUE) {
+ } else if (g_str_equal(key, "Domain")) {
dbus_message_iter_get_basic(&value, &str);
g_free(data->domain);
data->domain = g_strdup(str);
- } else if (g_str_equal(key, "Nameservers") == TRUE) {
+ } else if (g_str_equal(key, "Nameservers")) {
extract_nameservers(&value, data);
- } else if (g_str_equal(key, "Index") == TRUE) {
+ } else if (g_str_equal(key, "Index")) {
dbus_message_iter_get_basic(&value, &data->index);
- } else if (g_str_equal(key, "ServerRoutes") == TRUE) {
+ } else if (g_str_equal(key, "ServerRoutes")) {
/* Ignored */
- } else if (g_str_equal(key, "UserRoutes") == TRUE) {
+ } else if (g_str_equal(key, "UserRoutes")) {
/* Ignored */
} else {
if (dbus_message_iter_get_arg_type(&value) ==
@@ -635,7 +640,7 @@ static void add_connection(const char *path, DBusMessageIter *properties,
dbus_message_iter_next(properties);
}
- if (found == FALSE)
+ if (!found)
g_hash_table_insert(vpn_connections, g_strdup(data->ident),
data);
@@ -645,15 +650,15 @@ static void add_connection(const char *path, DBusMessageIter *properties,
resolv_host_addr(data);
- if (data->nameservers != NULL)
+ if (data->nameservers)
connman_provider_set_nameservers(data->provider,
data->nameservers);
- if (data->domain != NULL)
+ if (data->domain)
connman_provider_set_domain(data->provider,
data->domain);
- if (data->connect_pending == TRUE)
+ if (data->connect_pending)
connect_provider(data, data->cb_data);
return;
@@ -678,7 +683,7 @@ static void get_connections_reply(DBusPendingCall *call, void *user_data)
DBUS_DICT_ENTRY_END_CHAR_AS_STRING
DBUS_STRUCT_END_CHAR_AS_STRING;
- if (dbus_pending_call_get_completed(call) == FALSE)
+ if (!dbus_pending_call_get_completed(call))
return;
DBG("");
@@ -687,20 +692,20 @@ static void get_connections_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);
goto done;
}
- if (dbus_message_has_signature(reply, signature) == FALSE) {
+ if (!dbus_message_has_signature(reply, signature)) {
connman_error("vpnd signature \"%s\" does not match "
"expected \"%s\"",
dbus_message_get_signature(reply), signature);
goto done;
}
- if (dbus_message_iter_init(reply, &array) == FALSE)
+ if (!dbus_message_iter_init(reply, &array))
goto done;
dbus_message_iter_recurse(&array, &dict);
@@ -736,18 +741,18 @@ static int get_connections(void *user_data)
message = dbus_message_new_method_call(VPN_SERVICE, "/",
VPN_MANAGER_INTERFACE,
GET_CONNECTIONS);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
- if (dbus_connection_send_with_reply(connection, message,
- &call, DBUS_TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &call, DBUS_TIMEOUT)) {
connman_error("Unable to call %s.%s()", VPN_MANAGER_INTERFACE,
GET_CONNECTIONS);
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
dbus_message_unref(message);
return -EINVAL;
}
@@ -770,7 +775,7 @@ static void remove_connection_reply(DBusPendingCall *call, void *user_data)
DBusMessage *reply;
DBusError error;
- if (dbus_pending_call_get_completed(call) == FALSE)
+ if (!dbus_pending_call_get_completed(call))
return;
DBG("");
@@ -779,13 +784,13 @@ static void remove_connection_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)) {
/*
* If the returned error is NotFound, it means that we
* have actually removed the provider in vpnd already.
*/
- if (dbus_error_has_name(&error, CONNMAN_ERROR_INTERFACE
- ".NotFound") == FALSE)
+ if (!dbus_error_has_name(&error,
+ CONNMAN_ERROR_INTERFACE".NotFound"))
connman_error("%s", error.message);
dbus_error_free(&error);
@@ -806,7 +811,7 @@ static int provider_remove(struct connman_provider *provider)
DBG("provider %p data %p", provider, data);
- if (data == NULL) {
+ if (!data) {
/*
* This means the provider is already removed,
* just ignore the dbus in this case.
@@ -825,21 +830,21 @@ static int provider_remove(struct connman_provider *provider)
message = dbus_message_new_method_call(VPN_SERVICE, "/",
VPN_MANAGER_INTERFACE,
VPN_REMOVE);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH, &data->path,
NULL);
- if (dbus_connection_send_with_reply(connection, message,
- &call, DBUS_TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &call, DBUS_TIMEOUT)) {
connman_error("Unable to call %s.%s()", VPN_MANAGER_INTERFACE,
VPN_REMOVE);
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
dbus_message_unref(message);
return -EINVAL;
}
@@ -857,7 +862,7 @@ static int provider_connect(struct connman_provider *provider)
struct connection_data *data;
data = connman_provider_get_data(provider);
- if (data == NULL)
+ if (!data)
return -EINVAL;
return connect_provider(data, NULL);
@@ -868,7 +873,7 @@ static void disconnect_reply(DBusPendingCall *call, void *user_data)
DBusMessage *reply;
DBusError error;
- if (dbus_pending_call_get_completed(call) == FALSE)
+ if (!dbus_pending_call_get_completed(call))
return;
DBG("user %p", user_data);
@@ -877,7 +882,7 @@ static void disconnect_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);
goto done;
@@ -899,18 +904,18 @@ static int disconnect_provider(struct connection_data *data)
message = dbus_message_new_method_call(VPN_SERVICE, data->path,
VPN_CONNECTION_INTERFACE,
VPN_DISCONNECT);
- if (message == NULL)
+ if (!message)
return -ENOMEM;
- if (dbus_connection_send_with_reply(connection, message,
- &call, DBUS_TIMEOUT) == FALSE) {
+ if (!dbus_connection_send_with_reply(connection, message,
+ &call, DBUS_TIMEOUT)) {
connman_error("Unable to call %s.%s()",
VPN_CONNECTION_INTERFACE, VPN_DISCONNECT);
dbus_message_unref(message);
return -EINVAL;
}
- if (call == NULL) {
+ if (!call) {
dbus_message_unref(message);
return -EINVAL;
}
@@ -938,11 +943,11 @@ static int provider_disconnect(struct connman_provider *provider)
DBG("provider %p", provider);
data = connman_provider_get_data(provider);
- if (data == NULL)
+ if (!data)
return -EINVAL;
- if (g_str_equal(data->state, "ready") == TRUE ||
- g_str_equal(data->state, "configuration") == TRUE)
+ if (g_str_equal(data->state, "ready") ||
+ g_str_equal(data->state, "configuration"))
return disconnect_provider(data);
return 0;
@@ -959,7 +964,7 @@ static void configuration_create_reply(DBusPendingCall *call, void *user_data)
struct connection_data *data;
struct config_create_data *cb_data = user_data;
- if (dbus_pending_call_get_completed(call) == FALSE)
+ if (!dbus_pending_call_get_completed(call))
return;
DBG("user %p", cb_data);
@@ -968,20 +973,20 @@ static void configuration_create_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("dbus error: %s", error.message);
dbus_error_free(&error);
goto done;
}
- if (dbus_message_has_signature(reply, signature) == FALSE) {
+ if (!dbus_message_has_signature(reply, signature)) {
connman_error("vpn configuration signature \"%s\" does not "
"match expected \"%s\"",
dbus_message_get_signature(reply), signature);
goto done;
}
- if (dbus_message_iter_init(reply, &iter) == FALSE)
+ if (!dbus_message_iter_init(reply, &iter))
goto done;
dbus_message_iter_get_basic(&iter, &path);
@@ -992,16 +997,16 @@ static void configuration_create_reply(DBusPendingCall *call, void *user_data)
ident = get_ident(path);
data = g_hash_table_lookup(vpn_connections, ident);
- if (data == NULL) {
+ if (!data) {
/*
* Someone removed the data. We cannot really continue.
*/
DBG("Pending data not found for %s, cannot continue!", ident);
} else {
data->call = NULL;
- data->connect_pending = TRUE;
+ data->connect_pending = true;
- if (data->cb_data == NULL)
+ if (!data->cb_data)
data->cb_data = cb_data;
else
DBG("Connection callback data already in use!");
@@ -1043,33 +1048,33 @@ static struct vpn_route *parse_user_route(const char *user_route)
int family = PF_UNSPEC;
char **elems = g_strsplit(user_route, "/", 0);
- if (elems == NULL)
+ if (!elems)
return NULL;
network = elems[0];
- if (network == NULL || *network == '\0') {
+ if (!network || *network == '\0') {
DBG("no network/netmask set");
goto out;
}
netmask = elems[1];
- if (netmask != NULL && *netmask == '\0') {
+ if (netmask && *netmask == '\0') {
DBG("no netmask set");
goto out;
}
- if (g_strrstr(network, ":") != NULL)
+ if (g_strrstr(network, ":"))
family = AF_INET6;
- else if (g_strrstr(network, ".") != NULL) {
+ else if (g_strrstr(network, ".")) {
family = AF_INET;
- if (g_strrstr(netmask, ".") == NULL) {
+ if (!g_strrstr(netmask, ".")) {
/* We have netmask length */
in_addr_t addr;
struct in_addr netmask_in;
unsigned char prefix_len = 32;
- if (netmask != NULL) {
+ if (netmask) {
char *ptr;
long int value = strtol(netmask, &ptr, 10);
if (ptr != netmask && *ptr == '\0' &&
@@ -1086,7 +1091,7 @@ static struct vpn_route *parse_user_route(const char *user_route)
}
route = g_try_new(struct vpn_route, 1);
- if (route == NULL)
+ if (!route)
goto out;
route->network = g_strdup(network);
@@ -1113,7 +1118,7 @@ static GSList *get_user_networks(DBusMessageIter *array)
dbus_message_iter_get_basic(&entry, &val);
route = parse_user_route(val);
- if (route != NULL)
+ if (route)
list = g_slist_prepend(list, route);
dbus_message_iter_next(&entry);
@@ -1130,7 +1135,7 @@ static void append_route(DBusMessageIter *iter, void *user_data)
connman_dbus_dict_open(iter, &item);
- if (route == NULL)
+ if (!route)
goto empty_dict;
if (route->family == AF_INET)
@@ -1142,15 +1147,15 @@ static void append_route(DBusMessageIter *iter, void *user_data)
connman_dbus_dict_append_basic(&item, "ProtocolFamily",
DBUS_TYPE_INT32, &family);
- if (route->network != NULL)
+ if (route->network)
connman_dbus_dict_append_basic(&item, "Network",
DBUS_TYPE_STRING, &route->network);
- if (route->netmask != NULL)
+ if (route->netmask)
connman_dbus_dict_append_basic(&item, "Netmask",
DBUS_TYPE_STRING, &route->netmask);
- if (route->gateway != NULL)
+ if (route->gateway)
connman_dbus_dict_append_basic(&item, "Gateway",
DBUS_TYPE_STRING, &route->gateway);
@@ -1164,7 +1169,7 @@ static void append_routes(DBusMessageIter *iter, void *user_data)
DBG("routes %p", routes);
- for (list = routes; list != NULL; list = g_slist_next(list)) {
+ for (list = routes; list; list = g_slist_next(list)) {
DBusMessageIter dict;
struct vpn_route *route = list->data;
@@ -1220,24 +1225,23 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
case DBUS_TYPE_STRING:
dbus_message_iter_get_basic(&value, &item_value);
- if (g_str_equal(key, "Type") == TRUE) {
+ if (g_str_equal(key, "Type"))
type = (const char *)item_value;
- } else if (g_str_equal(key, "Name") == TRUE) {
+ else if (g_str_equal(key, "Name"))
name = (const char *)item_value;
- } else if (g_str_equal(key, "Host") == TRUE) {
+ else if (g_str_equal(key, "Host"))
host = (const char *)item_value;
- } else if (g_str_equal(key, "VPN.Domain") == TRUE) {
+ else if (g_str_equal(key, "VPN.Domain"))
domain = (const char *)item_value;
- }
DBG("%s %s", key, (char *)item_value);
- if (item_value != NULL)
+ if (item_value)
connman_dbus_dict_append_basic(&new_dict, key,
value_type, &item_value);
break;
case DBUS_TYPE_ARRAY:
- if (g_str_equal(key, "Networks") == TRUE) {
+ if (g_str_equal(key, "Networks")) {
networks = get_user_networks(&value);
connman_dbus_dict_append_array(&new_dict,
"UserRoutes",
@@ -1256,12 +1260,12 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
DBG("VPN type %s name %s host %s domain %s networks %p",
type, name, host, domain, networks);
- if (host == NULL || domain == NULL) {
+ if (!host || !domain) {
err = -EINVAL;
goto done;
}
- if (type == NULL || name == NULL) {
+ if (!type || !name) {
err = -EOPNOTSUPP;
goto done;
}
@@ -1272,8 +1276,8 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
DBG("ident %s", ident);
data = g_hash_table_lookup(vpn_connections, ident);
- if (data != NULL) {
- if (data->call != NULL || data->cb_data != NULL) {
+ if (data) {
+ if (data->call || data->cb_data) {
DBG("create configuration call already pending");
err = -EINPROGRESS;
goto done;
@@ -1284,7 +1288,7 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
data = create_connection_data(path);
g_free(path);
- if (data == NULL) {
+ if (!data) {
err = -ENOMEM;
goto done;
}
@@ -1305,7 +1309,7 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
dbus_message_set_member(new_msg, "Create");
user_data = g_try_new0(struct config_create_data, 1);
- if (user_data == NULL) {
+ if (!user_data) {
err = -ENOMEM;
goto done;
}
@@ -1318,7 +1322,7 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
result = dbus_connection_send_with_reply(connection, new_msg,
&call, DBUS_TIMEOUT);
- if (result == FALSE || call == NULL) {
+ if (!result || !call) {
err = -EIO;
goto done;
}
@@ -1328,29 +1332,29 @@ static int create_configuration(DBusMessage *msg, connection_ready_cb callback)
data->call = call;
done:
- if (new_msg != NULL)
+ if (new_msg)
dbus_message_unref(new_msg);
- if (networks != NULL)
+ if (networks)
g_slist_free_full(networks, destroy_route);
g_free(me);
return err;
}
-static connman_bool_t check_host(char **hosts, char *host)
+static bool check_host(char **hosts, char *host)
{
int i;
- if (hosts == NULL)
- return FALSE;
+ if (!hosts)
+ return false;
- for (i = 0; hosts[i] != NULL; i++) {
+ for (i = 0; hosts[i]; i++) {
if (g_strcmp0(hosts[i], host) == 0)
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
static void set_route(struct connection_data *data, struct vpn_route *route)
@@ -1360,7 +1364,7 @@ static void set_route(struct connection_data *data, struct vpn_route *route)
* VPN server, then we must discard that because the
* server cannot be contacted via VPN tunnel.
*/
- if (check_host(data->host_ip, route->network) == TRUE) {
+ if (check_host(data->host_ip, route->network)) {
DBG("Discarding VPN route to %s via %s at index %d",
route->network, route->gateway, data->index);
return;
@@ -1390,14 +1394,14 @@ static int set_routes(struct connman_provider *provider,
DBG("provider %p", provider);
data = connman_provider_get_data(provider);
- if (data == NULL)
+ if (!data)
return -EINVAL;
if (type == CONNMAN_PROVIDER_ROUTE_ALL ||
type == CONNMAN_PROVIDER_ROUTE_USER) {
g_hash_table_iter_init(&iter, data->user_routes);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE)
+ while (g_hash_table_iter_next(&iter, &key, &value))
set_route(data, value);
}
@@ -1405,32 +1409,32 @@ static int set_routes(struct connman_provider *provider,
type == CONNMAN_PROVIDER_ROUTE_SERVER) {
g_hash_table_iter_init(&iter, data->server_routes);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE)
+ while (g_hash_table_iter_next(&iter, &key, &value))
set_route(data, value);
}
return 0;
}
-static connman_bool_t check_routes(struct connman_provider *provider)
+static bool check_routes(struct connman_provider *provider)
{
struct connection_data *data;
DBG("provider %p", provider);
data = connman_provider_get_data(provider);
- if (data == NULL)
- return FALSE;
+ if (!data)
+ return false;
- if (data->user_routes != NULL &&
+ if (data->user_routes &&
g_hash_table_size(data->user_routes) > 0)
- return TRUE;
+ return true;
- if (data->server_routes != NULL &&
+ if (data->server_routes &&
g_hash_table_size(data->server_routes) > 0)
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
static struct connman_provider_driver provider_driver = {
@@ -1451,11 +1455,11 @@ static void destroy_provider(struct connection_data *data)
{
DBG("data %p", data);
- if (g_str_equal(data->state, "ready") == TRUE ||
- g_str_equal(data->state, "configuration") == TRUE)
+ if (g_str_equal(data->state, "ready") ||
+ g_str_equal(data->state, "configuration"))
connman_provider_disconnect(data->provider);
- if (data->call != NULL)
+ if (data->call)
dbus_pending_call_cancel(data->call);
connman_provider_set_data(data->provider, NULL);
@@ -1471,7 +1475,7 @@ static void connection_destroy(gpointer hash_data)
DBG("data %p", data);
- if (data->provider != NULL)
+ if (data->provider)
destroy_provider(data);
g_free(data->path);
@@ -1521,7 +1525,7 @@ static gboolean connection_removed(DBusConnection *conn, DBusMessage *message,
const char *signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
struct connection_data *data;
- if (dbus_message_has_signature(message, signature) == FALSE) {
+ if (!dbus_message_has_signature(message, signature)) {
connman_error("vpn removed signature \"%s\" does not match "
"expected \"%s\"",
dbus_message_get_signature(message), signature);
@@ -1532,7 +1536,7 @@ static gboolean connection_removed(DBusConnection *conn, DBusMessage *message,
DBUS_TYPE_INVALID);
data = g_hash_table_lookup(vpn_connections, get_ident(path));
- if (data != NULL)
+ if (data)
remove_connection(conn, path);
return TRUE;
@@ -1550,7 +1554,7 @@ static gboolean connection_added(DBusConnection *conn, DBusMessage *message,
DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
- if (dbus_message_has_signature(message, signature) == FALSE) {
+ if (!dbus_message_has_signature(message, signature)) {
connman_error("vpn ConnectionAdded signature \"%s\" does not "
"match expected \"%s\"",
dbus_message_get_signature(message), signature);
@@ -1559,7 +1563,7 @@ static gboolean connection_added(DBusConnection *conn, DBusMessage *message,
DBG("");
- if (dbus_message_iter_init(message, &iter) == FALSE)
+ if (!dbus_message_iter_init(message, &iter))
return TRUE;
dbus_message_iter_get_basic(&iter, &path);
@@ -1581,9 +1585,9 @@ static int save_route(GHashTable *routes, int family, const char *network,
DBG("family %d network %s netmask %s", family, network, netmask);
route = g_hash_table_lookup(routes, key);
- if (route == NULL) {
+ if (!route) {
route = g_try_new0(struct vpn_route, 1);
- if (route == NULL) {
+ if (!route) {
connman_error("out of memory");
return -ENOMEM;
}
@@ -1622,7 +1626,7 @@ static int read_route_dict(GHashTable *routes, DBusMessageIter *dicts)
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "ProtocolFamily") == TRUE) {
+ if (g_str_equal(key, "ProtocolFamily")) {
int pf;
dbus_message_iter_get_basic(&value, &pf);
switch (pf) {
@@ -1634,13 +1638,13 @@ static int read_route_dict(GHashTable *routes, DBusMessageIter *dicts)
break;
}
DBG("family %d", family);
- } else if (g_str_equal(key, "Netmask") == TRUE) {
+ } else if (g_str_equal(key, "Netmask")) {
dbus_message_iter_get_basic(&value, &netmask);
DBG("netmask %s", netmask);
- } else if (g_str_equal(key, "Network") == TRUE) {
+ } else if (g_str_equal(key, "Network")) {
dbus_message_iter_get_basic(&value, &network);
DBG("host %s", network);
- } else if (g_str_equal(key, "Gateway") == TRUE) {
+ } else if (g_str_equal(key, "Gateway")) {
dbus_message_iter_get_basic(&value, &gateway);
DBG("gateway %s", gateway);
}
@@ -1648,7 +1652,7 @@ static int read_route_dict(GHashTable *routes, DBusMessageIter *dicts)
dbus_message_iter_next(&dict);
}
- if (netmask == NULL || network == NULL || gateway == NULL) {
+ if (!netmask || !network || !gateway) {
DBG("Value missing.");
return -EINVAL;
}
@@ -1700,14 +1704,14 @@ static gboolean property_changed(DBusConnection *conn,
const char *path = dbus_message_get_path(message);
struct connection_data *data = NULL;
DBusMessageIter iter, value;
- connman_bool_t ip_set = FALSE;
+ bool ip_set = false;
int err;
char *str;
const char *key;
const char *signature = DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_VARIANT_AS_STRING;
- if (dbus_message_has_signature(message, signature) == FALSE) {
+ if (!dbus_message_has_signature(message, signature)) {
connman_error("vpn property signature \"%s\" does not match "
"expected \"%s\"",
dbus_message_get_signature(message), signature);
@@ -1715,10 +1719,10 @@ static gboolean property_changed(DBusConnection *conn,
}
data = g_hash_table_lookup(vpn_connections, get_ident(path));
- if (data == NULL)
+ if (!data)
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);
@@ -1728,28 +1732,28 @@ static gboolean property_changed(DBusConnection *conn,
DBG("key %s", key);
- if (g_str_equal(key, "State") == TRUE) {
+ if (g_str_equal(key, "State")) {
dbus_message_iter_get_basic(&value, &str);
DBG("%s %s -> %s", data->path, data->state, str);
- if (g_str_equal(data->state, str) == TRUE)
+ if (g_str_equal(data->state, str))
return TRUE;
g_free(data->state);
data->state = g_strdup(str);
set_provider_state(data);
- } else if (g_str_equal(key, "Index") == TRUE) {
+ } else if (g_str_equal(key, "Index")) {
dbus_message_iter_get_basic(&value, &data->index);
connman_provider_set_index(data->provider, data->index);
- } else if (g_str_equal(key, "IPv4") == TRUE) {
+ } else if (g_str_equal(key, "IPv4")) {
err = extract_ip(&value, AF_INET, data);
- ip_set = TRUE;
- } else if (g_str_equal(key, "IPv6") == TRUE) {
+ ip_set = true;
+ } else if (g_str_equal(key, "IPv6")) {
err = extract_ip(&value, AF_INET6, data);
- ip_set = TRUE;
- } else if (g_str_equal(key, "ServerRoutes") == TRUE) {
+ ip_set = true;
+ } else if (g_str_equal(key, "ServerRoutes")) {
err = routes_changed(&value, data->server_routes);
/*
* Note that the vpnd will delay the route sending a bit
@@ -1761,24 +1765,24 @@ static gboolean property_changed(DBusConnection *conn,
if (err == 0)
set_routes(data->provider,
CONNMAN_PROVIDER_ROUTE_SERVER);
- } else if (g_str_equal(key, "UserRoutes") == TRUE) {
+ } else if (g_str_equal(key, "UserRoutes")) {
err = routes_changed(&value, data->user_routes);
if (err == 0)
set_routes(data->provider,
CONNMAN_PROVIDER_ROUTE_USER);
- } else if (g_str_equal(key, "Nameservers") == TRUE) {
+ } else if (g_str_equal(key, "Nameservers")) {
if (extract_nameservers(&value, data) == 0 &&
- data->nameservers != NULL)
+ data->nameservers)
connman_provider_set_nameservers(data->provider,
data->nameservers);
- } else if (g_str_equal(key, "Domain") == TRUE) {
+ } else if (g_str_equal(key, "Domain")) {
dbus_message_iter_get_basic(&value, &str);
g_free(data->domain);
data->domain = g_strdup(str);
connman_provider_set_domain(data->provider, data->domain);
}
- if (ip_set == TRUE && err == 0) {
+ if (ip_set && err == 0) {
err = connman_provider_set_ipaddress(data->provider, data->ip);
if (err < 0)
DBG("setting provider IP address failed (%s/%d)",
@@ -1793,7 +1797,7 @@ static int vpn_init(void)
int err;
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
watch = g_dbus_add_service_watch(connection, VPN_SERVICE,
@@ -1850,7 +1854,7 @@ static void vpn_exit(void)
connman_provider_driver_unregister(&provider_driver);
- if (vpn_connections != NULL)
+ if (vpn_connections)
g_hash_table_destroy(vpn_connections);
dbus_connection_unref(connection);
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 5f078692..ef4dd951 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2,7 +2,7 @@
*
* Connection Manager
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2014 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
@@ -48,6 +48,7 @@
#include <connman/rtnl.h>
#include <connman/technology.h>
#include <connman/service.h>
+#include <connman/peer.h>
#include <connman/log.h>
#include <connman/option.h>
#include <connman/storage.h>
@@ -58,19 +59,23 @@
#define CLEANUP_TIMEOUT 8 /* in seconds */
#define INACTIVE_TIMEOUT 12 /* in seconds */
-#define MAXIMUM_RETRIES 2
-#define FAVORITE_MAXIMUM_RETRIES 4
+#define FAVORITE_MAXIMUM_RETRIES 2
#define BGSCAN_DEFAULT "simple:30:-45:300"
#define AUTOSCAN_DEFAULT "exponential:3:300"
+#define P2P_FIND_TIMEOUT 30
+
static struct connman_technology *wifi_technology = NULL;
+static struct connman_technology *p2p_technology = NULL;
struct hidden_params {
char ssid[32];
unsigned int ssid_len;
char *identity;
char *passphrase;
+ char *security;
+ GSupplicantScanParams *scan_params;
gpointer user_data;
};
@@ -93,37 +98,59 @@ struct wifi_data {
GSList *networks;
GSupplicantInterface *interface;
GSupplicantState state;
- connman_bool_t connected;
- connman_bool_t disconnecting;
- connman_bool_t tethering;
- connman_bool_t bridged;
+ bool connected;
+ bool disconnecting;
+ bool tethering;
+ bool bridged;
+ bool interface_ready;
const char *bridge;
int index;
unsigned flags;
unsigned int watch;
int retries;
struct hidden_params *hidden;
+ bool postpone_hidden;
/**
* autoscan "emulation".
*/
struct autoscan_params *autoscan;
GSupplicantScanParams *scan_params;
+ unsigned int p2p_find_timeout;
};
static GList *iface_list = NULL;
static void start_autoscan(struct connman_device *device);
+static int p2p_tech_probe(struct connman_technology *technology)
+{
+ p2p_technology = technology;
+
+ return 0;
+}
+
+static void p2p_tech_remove(struct connman_technology *technology)
+{
+ p2p_technology = NULL;
+}
+
+static struct connman_technology_driver p2p_tech_driver = {
+ .name = "p2p",
+ .type = CONNMAN_SERVICE_TYPE_P2P,
+ .probe = p2p_tech_probe,
+ .remove = p2p_tech_remove,
+};
+
static void handle_tethering(struct wifi_data *wifi)
{
- if (wifi->tethering == FALSE)
+ if (!wifi->tethering)
return;
- if (wifi->bridge == NULL)
+ if (!wifi->bridge)
return;
- if (wifi->bridged == TRUE)
+ if (wifi->bridged)
return;
DBG("index %d bridge %s", wifi->index, wifi->bridge);
@@ -131,7 +158,7 @@ static void handle_tethering(struct wifi_data *wifi)
if (connman_inet_add_to_bridge(wifi->index, wifi->bridge) < 0)
return;
- wifi->bridged = TRUE;
+ wifi->bridged = true;
}
static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
@@ -139,7 +166,7 @@ static void wifi_newlink(unsigned flags, unsigned change, void *user_data)
struct connman_device *device = user_data;
struct wifi_data *wifi = connman_device_get_data(device);
- if (wifi == NULL)
+ if (!wifi)
return;
DBG("index %d flags %d change %d", wifi->index, flags, change);
@@ -170,14 +197,9 @@ static int wifi_probe(struct connman_device *device)
DBG("device %p", device);
wifi = g_try_new0(struct wifi_data, 1);
- if (wifi == NULL)
+ if (!wifi)
return -ENOMEM;
- wifi->connected = FALSE;
- wifi->disconnecting = FALSE;
- wifi->tethering = FALSE;
- wifi->bridged = FALSE;
- wifi->bridge = NULL;
wifi->state = G_SUPPLICANT_STATE_INACTIVE;
connman_device_set_data(device, wifi);
@@ -199,7 +221,7 @@ static void remove_networks(struct connman_device *device,
{
GSList *list;
- for (list = wifi->networks; list != NULL; list = list->next) {
+ for (list = wifi->networks; list; list = list->next) {
struct connman_network *network = list->data;
connman_device_remove_network(device, network);
@@ -217,7 +239,7 @@ static void reset_autoscan(struct connman_device *device)
DBG("");
- if (wifi == NULL || wifi->autoscan == NULL)
+ if (!wifi || !wifi->autoscan)
return;
autoscan = wifi->autoscan;
@@ -237,12 +259,29 @@ static void stop_autoscan(struct connman_device *device)
{
const struct wifi_data *wifi = connman_device_get_data(device);
- if (wifi == NULL || wifi->autoscan == NULL)
+ if (!wifi || !wifi->autoscan)
return;
reset_autoscan(device);
- connman_device_set_scanning(device, FALSE);
+ connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_WIFI, false);
+}
+
+static void check_p2p_technology(void)
+{
+ bool p2p_exists = false;
+ GList *list;
+
+ for (list = iface_list; list; list = list->next) {
+ struct wifi_data *w = list->data;
+
+ if (w->interface &&
+ g_supplicant_interface_has_p2p(w->interface))
+ p2p_exists = true;
+ }
+
+ if (!p2p_exists)
+ connman_technology_driver_unregister(&p2p_tech_driver);
}
static void wifi_remove(struct connman_device *device)
@@ -251,21 +290,30 @@ static void wifi_remove(struct connman_device *device)
DBG("device %p wifi %p", device, wifi);
- if (wifi == NULL)
+ if (!wifi)
return;
+ stop_autoscan(device);
+
iface_list = g_list_remove(iface_list, wifi);
+ check_p2p_technology();
+
+ if (wifi->p2p_find_timeout) {
+ g_source_remove(wifi->p2p_find_timeout);
+ connman_device_unref(wifi->device);
+ }
+
remove_networks(device, wifi);
- connman_device_set_powered(device, FALSE);
+ connman_device_set_powered(device, false);
connman_device_set_data(device, NULL);
connman_device_unref(wifi->device);
connman_rtnl_remove_watch(wifi->watch);
g_supplicant_interface_set_data(wifi->interface, NULL);
- if (wifi->scan_params != NULL)
+ if (wifi->scan_params)
g_supplicant_free_scan_params(wifi->scan_params);
g_free(wifi->autoscan);
@@ -273,19 +321,19 @@ static void wifi_remove(struct connman_device *device)
g_free(wifi);
}
-static gboolean is_duplicate(GSList *list, gchar *ssid, int ssid_len)
+static bool is_duplicate(GSList *list, gchar *ssid, int ssid_len)
{
GSList *iter;
- for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
+ for (iter = list; iter; iter = g_slist_next(iter)) {
struct scan_ssid *scan_ssid = iter->data;
if (ssid_len == scan_ssid->ssid_len &&
memcmp(ssid, scan_ssid->ssid, ssid_len) == 0)
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
@@ -297,15 +345,15 @@ static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
if ((driver_max_scan_ssids == 0 ||
driver_max_scan_ssids > scan_data->num_ssids) &&
- (hex_ssid != NULL || raw_ssid != NULL)) {
+ (hex_ssid || raw_ssid)) {
gchar *ssid;
unsigned int j = 0, hex;
- if (hex_ssid != NULL) {
+ if (hex_ssid) {
size_t hex_ssid_len = strlen(hex_ssid);
ssid = g_try_malloc0(hex_ssid_len / 2);
- if (ssid == NULL)
+ if (!ssid)
return -ENOMEM;
for (i = 0; i < hex_ssid_len; i += 2) {
@@ -323,12 +371,16 @@ static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
* used or are using multiple wifi cards, so in that case
* you might have multiple service files for same AP.
*/
- if (is_duplicate(scan_data->ssids, ssid, j) == TRUE)
+ if (is_duplicate(scan_data->ssids, ssid, j)) {
+ if (hex_ssid)
+ g_free(ssid);
return 0;
+ }
scan_ssid = g_try_new(struct scan_ssid, 1);
- if (scan_ssid == NULL) {
- g_free(ssid);
+ if (!scan_ssid) {
+ if (hex_ssid)
+ g_free(ssid);
return -ENOMEM;
}
@@ -342,16 +394,16 @@ static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
DBG("SSID %s added to scanned list of %d entries", ssid_name,
scan_data->num_ssids);
- if (hex_ssid != NULL)
+ if (hex_ssid)
g_free(ssid);
} else
return -EINVAL;
scan_data->ssids = g_slist_reverse(scan_data->ssids);
- if (scan_data->freqs == NULL) {
+ if (!scan_data->freqs) {
scan_data->freqs = g_try_malloc0(sizeof(uint16_t));
- if (scan_data->freqs == NULL) {
+ if (!scan_data->freqs) {
g_slist_free_full(scan_data->ssids, g_free);
return -ENOMEM;
}
@@ -359,21 +411,21 @@ static int add_scan_param(gchar *hex_ssid, char *raw_ssid, int ssid_len,
scan_data->num_freqs = 1;
scan_data->freqs[0] = freq;
} else {
- connman_bool_t duplicate = FALSE;
+ bool duplicate = false;
/* Don't add duplicate entries */
for (i = 0; i < scan_data->num_freqs; i++) {
if (scan_data->freqs[i] == freq) {
- duplicate = TRUE;
+ duplicate = true;
break;
}
}
- if (duplicate == FALSE) {
+ if (!duplicate) {
scan_data->num_freqs++;
scan_data->freqs = g_try_realloc(scan_data->freqs,
sizeof(uint16_t) * scan_data->num_freqs);
- if (scan_data->freqs == NULL) {
+ if (!scan_data->freqs) {
g_slist_free_full(scan_data->ssids, g_free);
return -ENOMEM;
}
@@ -391,7 +443,7 @@ static int get_hidden_connections(GSupplicantScanParams *scan_data)
gchar **services;
char *ssid, *name;
int i, freq, ret;
- gboolean value;
+ bool value;
int num_ssids = 0, add_param_failed = 0;
services = connman_storage_get_services();
@@ -400,19 +452,19 @@ static int get_hidden_connections(GSupplicantScanParams *scan_data)
continue;
keyfile = connman_storage_load_service(services[i]);
- if (keyfile == NULL)
+ if (!keyfile)
continue;
value = g_key_file_get_boolean(keyfile,
services[i], "Hidden", NULL);
- if (value == FALSE) {
+ if (!value) {
g_key_file_free(keyfile);
continue;
}
value = g_key_file_get_boolean(keyfile,
services[i], "Favorite", NULL);
- if (value == FALSE) {
+ if (!value) {
g_key_file_free(keyfile);
continue;
}
@@ -444,10 +496,10 @@ static int get_hidden_connections(GSupplicantScanParams *scan_data)
for (i = 0; entries && entries[i]; i++) {
int len;
- if (entries[i]->hidden == FALSE)
+ if (!entries[i]->hidden)
continue;
- if (entries[i]->ssid == NULL) {
+ if (!entries[i]->ssid) {
ssid = entries[i]->name;
len = strlen(ssid);
} else {
@@ -455,7 +507,7 @@ static int get_hidden_connections(GSupplicantScanParams *scan_data)
len = entries[i]->ssid_len;
}
- if (ssid == NULL)
+ if (!ssid)
continue;
ret = add_scan_param(NULL, ssid, len, 0, scan_data, 0, ssid);
@@ -493,9 +545,9 @@ static int get_hidden_connections_params(struct wifi_data *wifi,
DBG("max ssids %d", driver_max_ssids);
- if (wifi->scan_params == NULL) {
+ if (!wifi->scan_params) {
wifi->scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
- if (wifi->scan_params == NULL)
+ if (!wifi->scan_params)
return 0;
if (get_hidden_connections(wifi->scan_params) == 0) {
@@ -512,7 +564,7 @@ static int get_hidden_connections_params(struct wifi_data *wifi,
for (i = 0; i < driver_max_ssids; i++) {
struct scan_ssid *ssid;
- if (wifi->scan_params->ssids == NULL)
+ if (!wifi->scan_params->ssids)
break;
ssid = orig_params->ssids->data;
@@ -526,7 +578,7 @@ static int get_hidden_connections_params(struct wifi_data *wifi,
scan_params->freqs = g_memdup(orig_params->freqs,
sizeof(uint16_t) * orig_params->num_freqs);
- if (scan_params->freqs == NULL)
+ if (!scan_params->freqs)
goto err;
scan_params->num_freqs = orig_params->num_freqs;
@@ -552,24 +604,25 @@ static int throw_wifi_scan(struct connman_device *device,
struct wifi_data *wifi = connman_device_get_data(device);
int ret;
- if (wifi == NULL)
+ if (!wifi)
return -ENODEV;
DBG("device %p %p", device, wifi->interface);
- if (wifi->tethering == TRUE)
+ if (wifi->tethering)
return -EBUSY;
- if (connman_device_get_scanning(device) == TRUE)
+ if (connman_device_get_scanning(device))
return -EALREADY;
connman_device_ref(device);
ret = g_supplicant_interface_scan(wifi->interface, NULL,
callback, device);
- if (ret == 0)
- connman_device_set_scanning(device, TRUE);
- else
+ if (ret == 0) {
+ connman_device_set_scanning(device,
+ CONNMAN_SERVICE_TYPE_WIFI, true);
+ } else
connman_device_unref(device);
return ret;
@@ -577,11 +630,14 @@ static int throw_wifi_scan(struct connman_device *device,
static void hidden_free(struct hidden_params *hidden)
{
- if (hidden == NULL)
+ if (!hidden)
return;
+ if (hidden->scan_params)
+ g_supplicant_free_scan_params(hidden->scan_params);
g_free(hidden->identity);
g_free(hidden->passphrase);
+ g_free(hidden->security);
g_free(hidden);
}
@@ -590,18 +646,18 @@ static void scan_callback(int result, GSupplicantInterface *interface,
{
struct connman_device *device = user_data;
struct wifi_data *wifi = connman_device_get_data(device);
- connman_bool_t scanning;
+ bool scanning;
DBG("result %d wifi %p", result, wifi);
- if (wifi != NULL) {
- if (wifi->hidden != NULL) {
+ if (wifi) {
+ if (wifi->hidden && !wifi->postpone_hidden) {
connman_network_clear_hidden(wifi->hidden->user_data);
hidden_free(wifi->hidden);
wifi->hidden = NULL;
}
- if (wifi->scan_params != NULL) {
+ if (wifi->scan_params) {
g_supplicant_free_scan_params(wifi->scan_params);
wifi->scan_params = NULL;
}
@@ -610,10 +666,32 @@ static void scan_callback(int result, GSupplicantInterface *interface,
if (result < 0)
connman_device_reset_scanning(device);
+ /* User is connecting to a hidden AP, let's wait for finished event */
+ if (wifi && wifi->hidden && wifi->postpone_hidden) {
+ GSupplicantScanParams *scan_params;
+ int ret;
+
+ wifi->postpone_hidden = false;
+ scan_params = wifi->hidden->scan_params;
+ wifi->hidden->scan_params = NULL;
+
+ reset_autoscan(device);
+
+ ret = g_supplicant_interface_scan(wifi->interface, scan_params,
+ scan_callback, device);
+ if (ret == 0)
+ return;
+
+ /* On error, let's recall scan_callback, which will cleanup */
+ return scan_callback(ret, interface, user_data);
+ }
+
scanning = connman_device_get_scanning(device);
- if (scanning == TRUE)
- connman_device_set_scanning(device, FALSE);
+ if (scanning) {
+ connman_device_set_scanning(device,
+ CONNMAN_SERVICE_TYPE_WIFI, false);
+ }
if (result != -ENOLINK)
start_autoscan(device);
@@ -625,7 +703,7 @@ static void scan_callback(int result, GSupplicantInterface *interface,
* unreferenced the device, obviating the need to do it here.
*/
- if (scanning == TRUE)
+ if (scanning)
connman_device_unref(device);
}
@@ -639,11 +717,15 @@ static void scan_callback_hidden(int result,
DBG("result %d wifi %p", result, wifi);
- if (wifi == NULL)
+ if (!wifi)
+ goto out;
+
+ /* User is trying to connect to a hidden AP */
+ if (wifi->hidden && wifi->postpone_hidden)
goto out;
scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
- if (scan_params == NULL)
+ if (!scan_params)
goto out;
if (get_hidden_connections_params(wifi, scan_params) > 0) {
@@ -668,7 +750,7 @@ static gboolean autoscan_timeout(gpointer data)
struct autoscan_params *autoscan;
int interval;
- if (wifi == NULL)
+ if (!wifi)
return FALSE;
autoscan = wifi->autoscan;
@@ -702,11 +784,11 @@ static void start_autoscan(struct connman_device *device)
DBG("");
- if (wifi == NULL)
+ if (!wifi)
return;
autoscan = wifi->autoscan;
- if (autoscan == NULL)
+ if (!autoscan)
return;
if (autoscan->timeout > 0 || autoscan->interval > 0)
@@ -741,7 +823,7 @@ static struct autoscan_params *parse_autoscan_params(const char *params)
g_strfreev(list_params);
autoscan = g_try_malloc0(sizeof(struct autoscan_params));
- if (autoscan == NULL) {
+ if (!autoscan) {
DBG("Could not allocate memory for autoscan");
return NULL;
}
@@ -755,7 +837,7 @@ static struct autoscan_params *parse_autoscan_params(const char *params)
static void setup_autoscan(struct wifi_data *wifi)
{
- if (wifi->autoscan == NULL)
+ if (!wifi->autoscan)
wifi->autoscan = parse_autoscan_params(AUTOSCAN_DEFAULT);
start_autoscan(wifi->device);
@@ -773,35 +855,20 @@ static void interface_autoscan_callback(int result,
}
}
-static void interface_create_callback(int result,
- GSupplicantInterface *interface,
- void *user_data)
+static void finalize_interface_creation(struct wifi_data *wifi)
{
- struct wifi_data *wifi = user_data;
-
- DBG("result %d ifname %s, wifi %p", result,
- g_supplicant_interface_get_ifname(interface),
- wifi);
-
- if (result < 0 || wifi == NULL)
- return;
-
- wifi->interface = interface;
- g_supplicant_interface_set_data(interface, wifi);
-
- if (g_supplicant_interface_get_ready(interface) == FALSE)
- return;
+ GSupplicantInterface *interface = wifi->interface;
DBG("interface is ready wifi %p tethering %d", wifi, wifi->tethering);
- if (wifi->device == NULL) {
+ if (!wifi->device) {
connman_error("WiFi device not set");
return;
}
- connman_device_set_powered(wifi->device, TRUE);
+ connman_device_set_powered(wifi->device, true);
- if (connman_setting_get_bool("BackgroundScanning") == FALSE)
+ if (!connman_setting_get_bool("BackgroundScanning"))
return;
/* Setting up automatic scanning */
@@ -812,21 +879,48 @@ static void interface_create_callback(int result,
}
}
+static void interface_create_callback(int result,
+ GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct wifi_data *wifi = user_data;
+
+ DBG("result %d ifname %s, wifi %p", result,
+ g_supplicant_interface_get_ifname(interface),
+ wifi);
+
+ if (result < 0 || !wifi)
+ return;
+
+ wifi->interface = interface;
+ g_supplicant_interface_set_data(interface, wifi);
+
+ if (g_supplicant_interface_get_ready(interface)) {
+ wifi->interface_ready = true;
+ finalize_interface_creation(wifi);
+ }
+}
+
static int wifi_enable(struct connman_device *device)
{
struct wifi_data *wifi = connman_device_get_data(device);
- const char *interface = connman_device_get_string(device, "Interface");
+ int index;
+ char *interface;
const char *driver = connman_option_get_string("wifi");
int ret;
DBG("device %p %p", device, wifi);
- if (wifi == NULL)
+ index = connman_device_get_index(device);
+ if (!wifi || index < 0)
return -ENODEV;
+ interface = connman_inet_ifname(index);
ret = g_supplicant_interface_create(interface, driver, NULL,
interface_create_callback,
wifi);
+ g_free(interface);
+
if (ret < 0)
return ret;
@@ -840,20 +934,27 @@ static int wifi_disable(struct connman_device *device)
DBG("device %p wifi %p", device, wifi);
- if (wifi == NULL)
+ if (!wifi)
return -ENODEV;
- wifi->connected = FALSE;
- wifi->disconnecting = FALSE;
+ wifi->connected = false;
+ wifi->disconnecting = false;
- if (wifi->pending_network != NULL)
+ if (wifi->pending_network)
wifi->pending_network = NULL;
stop_autoscan(device);
+ if (wifi->p2p_find_timeout) {
+ g_source_remove(wifi->p2p_find_timeout);
+ wifi->p2p_find_timeout = 0;
+ connman_device_unref(wifi->device);
+ }
+
/* In case of a user scan, device is still referenced */
- if (connman_device_get_scanning(device) == TRUE) {
- connman_device_set_scanning(device, FALSE);
+ if (connman_device_get_scanning(device)) {
+ connman_device_set_scanning(device,
+ CONNMAN_SERVICE_TYPE_WIFI, false);
connman_device_unref(wifi->device);
}
@@ -910,7 +1011,7 @@ static int get_latest_connections(int max_ssids,
int num_ssids = 0;
latest_list = g_sequence_new(free_entry);
- if (latest_list == NULL)
+ if (!latest_list)
return -ENOMEM;
services = connman_storage_get_services();
@@ -919,14 +1020,13 @@ static int get_latest_connections(int max_ssids,
continue;
keyfile = connman_storage_load_service(services[i]);
- if (keyfile == NULL)
+ if (!keyfile)
continue;
str = g_key_file_get_string(keyfile,
services[i], "Favorite", NULL);
- if (str == NULL || g_strcmp0(str, "true")) {
- if (str)
- g_free(str);
+ if (!str || g_strcmp0(str, "true")) {
+ g_free(str);
g_key_file_free(keyfile);
continue;
}
@@ -934,9 +1034,8 @@ static int get_latest_connections(int max_ssids,
str = g_key_file_get_string(keyfile,
services[i], "AutoConnect", NULL);
- if (str == NULL || g_strcmp0(str, "true")) {
- if (str)
- g_free(str);
+ if (!str || g_strcmp0(str, "true")) {
+ g_free(str);
g_key_file_free(keyfile);
continue;
}
@@ -944,10 +1043,12 @@ static int get_latest_connections(int max_ssids,
str = g_key_file_get_string(keyfile,
services[i], "Modified", NULL);
- if (str != NULL) {
- g_time_val_from_iso8601(str, &modified);
- g_free(str);
+ if (!str) {
+ g_key_file_free(keyfile);
+ continue;
}
+ g_time_val_from_iso8601(str, &modified);
+ g_free(str);
ssid = g_key_file_get_string(keyfile,
services[i], "SSID", NULL);
@@ -956,7 +1057,7 @@ static int get_latest_connections(int max_ssids,
"Frequency", NULL);
if (freq) {
entry = g_try_new(struct last_connected, 1);
- if (entry == NULL) {
+ if (!entry) {
g_sequence_free(latest_list);
g_key_file_free(keyfile);
g_free(ssid);
@@ -1005,14 +1106,86 @@ static int wifi_scan_simple(struct connman_device *device)
return throw_wifi_scan(device, scan_callback_hidden);
}
+static gboolean p2p_find_stop(gpointer data)
+{
+ struct connman_device *device = data;
+ struct wifi_data *wifi = connman_device_get_data(device);
+
+ DBG("");
+
+ wifi->p2p_find_timeout = 0;
+
+ connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
+
+ g_supplicant_interface_p2p_stop_find(wifi->interface);
+
+ connman_device_unref(device);
+ reset_autoscan(device);
+
+ return FALSE;
+}
+
+static void p2p_find_callback(int result, GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct connman_device *device = user_data;
+ struct wifi_data *wifi = connman_device_get_data(device);
+
+ DBG("result %d wifi %p", result, wifi);
+
+ if (wifi->p2p_find_timeout) {
+ g_source_remove(wifi->p2p_find_timeout);
+ wifi->p2p_find_timeout = 0;
+ }
+
+ if (result)
+ goto error;
+
+ wifi->p2p_find_timeout = g_timeout_add_seconds(P2P_FIND_TIMEOUT,
+ p2p_find_stop, device);
+ if (!wifi->p2p_find_timeout)
+ goto error;
+
+ return;
+error:
+ p2p_find_stop(device);
+}
+
+static int p2p_find(struct connman_device *device)
+{
+ struct wifi_data *wifi = connman_device_get_data(device);
+ int ret;
+
+ DBG("");
+
+ if (!p2p_technology)
+ return -ENOTSUP;
+
+ reset_autoscan(device);
+ connman_device_ref(device);
+
+ ret = g_supplicant_interface_p2p_find(wifi->interface,
+ p2p_find_callback, device);
+ if (ret) {
+ connman_device_unref(device);
+ start_autoscan(device);
+ } else {
+ connman_device_set_scanning(device,
+ CONNMAN_SERVICE_TYPE_P2P, true);
+ }
+
+ return ret;
+}
+
/*
* Note that the hidden scan is only used when connecting to this specific
* hidden AP first time. It is not used when system autoconnects to hidden AP.
*/
-static int wifi_scan(struct connman_device *device,
- const char *ssid, unsigned int ssid_len,
- const char *identity, const char* passphrase,
- gpointer user_data)
+static int wifi_scan(enum connman_service_type type,
+ struct connman_device *device,
+ const char *ssid, unsigned int ssid_len,
+ const char *identity, const char* passphrase,
+ const char *security, void *user_data)
{
struct wifi_data *wifi = connman_device_get_data(device);
GSupplicantScanParams *scan_params = NULL;
@@ -1020,43 +1193,47 @@ static int wifi_scan(struct connman_device *device,
struct hidden_params *hidden;
int ret;
int driver_max_ssids = 0;
- connman_bool_t do_hidden;
+ bool do_hidden;
+ bool scanning;
- if (wifi == NULL)
+ if (!wifi)
return -ENODEV;
+ if (type == CONNMAN_SERVICE_TYPE_P2P)
+ return p2p_find(device);
+
DBG("device %p wifi %p hidden ssid %s", device, wifi->interface, ssid);
- if (wifi->tethering == TRUE)
+ if (wifi->tethering)
return 0;
- if (connman_device_get_scanning(device) == TRUE)
- return -EALREADY;
-
- if (ssid == NULL || ssid_len == 0 || ssid_len > 32) {
- do_hidden = FALSE;
- } else {
- if (wifi->hidden != NULL)
- return -EBUSY;
+ scanning = connman_device_get_scanning(device);
- do_hidden = TRUE;
- }
+ if (!ssid || ssid_len == 0 || ssid_len > 32) {
+ if (scanning)
+ return -EALREADY;
- if (do_hidden == FALSE) {
driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
wifi->interface);
DBG("max ssids %d", driver_max_ssids);
if (driver_max_ssids == 0)
return wifi_scan_simple(device);
+
+ do_hidden = false;
+ } else {
+ if (scanning && wifi->hidden && wifi->postpone_hidden)
+ return -EALREADY;
+
+ do_hidden = true;
}
scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
- if (scan_params == NULL)
+ if (!scan_params)
return -ENOMEM;
- if (do_hidden == TRUE) {
+ if (do_hidden) {
scan_ssid = g_try_new(struct scan_ssid, 1);
- if (scan_ssid == NULL) {
+ if (!scan_ssid) {
g_free(scan_params);
return -ENOMEM;
}
@@ -1068,18 +1245,32 @@ static int wifi_scan(struct connman_device *device,
scan_params->num_ssids = 1;
hidden = g_try_new0(struct hidden_params, 1);
- if (hidden == NULL) {
- g_free(scan_params);
+ if (!hidden) {
+ g_supplicant_free_scan_params(scan_params);
return -ENOMEM;
}
+ if (wifi->hidden) {
+ hidden_free(wifi->hidden);
+ wifi->hidden = NULL;
+ }
+
memcpy(hidden->ssid, ssid, ssid_len);
hidden->ssid_len = ssid_len;
hidden->identity = g_strdup(identity);
hidden->passphrase = g_strdup(passphrase);
+ hidden->security = g_strdup(security);
hidden->user_data = user_data;
wifi->hidden = hidden;
+ if (scanning) {
+ /* Let's keep this active scan for later,
+ * when current scan will be over. */
+ wifi->postpone_hidden = TRUE;
+ hidden->scan_params = scan_params;
+
+ return 0;
+ }
} else {
ret = get_latest_connections(driver_max_ssids, scan_params);
if (ret <= 0) {
@@ -1094,13 +1285,14 @@ static int wifi_scan(struct connman_device *device,
ret = g_supplicant_interface_scan(wifi->interface, scan_params,
scan_callback, device);
- if (ret == 0)
- connman_device_set_scanning(device, TRUE);
- else {
+ if (ret == 0) {
+ connman_device_set_scanning(device,
+ CONNMAN_SERVICE_TYPE_WIFI, true);
+ } else {
g_supplicant_free_scan_params(scan_params);
connman_device_unref(device);
- if (do_hidden == TRUE) {
+ if (do_hidden) {
hidden_free(wifi->hidden);
wifi->hidden = NULL;
}
@@ -1125,7 +1317,7 @@ static int wifi_set_regdom(struct connman_device *device, const char *alpha2)
struct wifi_data *wifi = connman_device_get_data(device);
int ret;
- if (wifi == NULL)
+ if (!wifi)
return -EINVAL;
connman_device_ref(device);
@@ -1181,7 +1373,7 @@ static void network_remove(struct connman_network *network)
DBG("network %p", network);
wifi = connman_device_get_data(device);
- if (wifi == NULL)
+ if (!wifi)
return;
if (wifi->network != network)
@@ -1204,21 +1396,23 @@ static void connect_callback(int result, GSupplicantInterface *interface,
connman_network_set_error(network,
CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
}
+
+ connman_network_unref(network);
}
static GSupplicantSecurity network_security(const char *security)
{
- if (g_str_equal(security, "none") == TRUE)
+ if (g_str_equal(security, "none"))
return G_SUPPLICANT_SECURITY_NONE;
- else if (g_str_equal(security, "wep") == TRUE)
+ else if (g_str_equal(security, "wep"))
return G_SUPPLICANT_SECURITY_WEP;
- else if (g_str_equal(security, "psk") == TRUE)
+ else if (g_str_equal(security, "psk"))
return G_SUPPLICANT_SECURITY_PSK;
- else if (g_str_equal(security, "wpa") == TRUE)
+ else if (g_str_equal(security, "wpa"))
return G_SUPPLICANT_SECURITY_PSK;
- else if (g_str_equal(security, "rsn") == TRUE)
+ else if (g_str_equal(security, "rsn"))
return G_SUPPLICANT_SECURITY_PSK;
- else if (g_str_equal(security, "ieee8021x") == TRUE)
+ else if (g_str_equal(security, "ieee8021x"))
return G_SUPPLICANT_SECURITY_IEEE8021X;
return G_SUPPLICANT_SECURITY_UNKNOWN;
@@ -1226,7 +1420,7 @@ static GSupplicantSecurity network_security(const char *security)
static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
{
- const char *security, *passphrase, *agent_passphrase;
+ const char *security;
memset(ssid, 0, sizeof(*ssid));
ssid->mode = G_SUPPLICANT_MODE_INFRA;
@@ -1235,20 +1429,8 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
ssid->scan_ssid = 1;
security = connman_network_get_string(network, "WiFi.Security");
ssid->security = network_security(security);
- passphrase = connman_network_get_string(network,
+ ssid->passphrase = connman_network_get_string(network,
"WiFi.Passphrase");
- if (passphrase == NULL || strlen(passphrase) == 0) {
-
- /* Use agent provided passphrase as a fallback */
- agent_passphrase = connman_network_get_string(network,
- "WiFi.AgentPassphrase");
-
- if (agent_passphrase == NULL || strlen(agent_passphrase) == 0)
- ssid->passphrase = NULL;
- else
- ssid->passphrase = agent_passphrase;
- } else
- ssid->passphrase = passphrase;
ssid->eap = connman_network_get_string(network, "WiFi.EAP");
@@ -1258,8 +1440,7 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
* for PEAP where 2 passphrases (identity and client
* cert may have to be provided.
*/
- if (connman_network_get_string(network,
- "WiFi.PrivateKeyPassphrase") == NULL)
+ if (!connman_network_get_string(network, "WiFi.PrivateKeyPassphrase"))
connman_network_set_string(network,
"WiFi.PrivateKeyPassphrase",
ssid->passphrase);
@@ -1267,7 +1448,7 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
ssid->identity = connman_network_get_string(network, "WiFi.Identity");
/* Use agent provided identity as a fallback */
- if (ssid->identity == NULL || strlen(ssid->identity) == 0)
+ if (!ssid->identity || strlen(ssid->identity) == 0)
ssid->identity = connman_network_get_string(network,
"WiFi.AgentIdentity");
@@ -1284,7 +1465,7 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
- if (connman_setting_get_bool("BackgroundScanning") == TRUE)
+ if (connman_setting_get_bool("BackgroundScanning"))
ssid->bgscan = BGSCAN_DEFAULT;
}
@@ -1297,25 +1478,26 @@ static int network_connect(struct connman_network *network)
DBG("network %p", network);
- if (device == NULL)
+ if (!device)
return -ENODEV;
wifi = connman_device_get_data(device);
- if (wifi == NULL)
+ if (!wifi)
return -ENODEV;
ssid = g_try_malloc0(sizeof(GSupplicantSSID));
- if (ssid == NULL)
+ if (!ssid)
return -ENOMEM;
interface = wifi->interface;
ssid_init(ssid, network);
- if (wifi->disconnecting == TRUE)
+ if (wifi->disconnecting) {
wifi->pending_network = network;
- else {
- wifi->network = network;
+ g_free(ssid);
+ } else {
+ wifi->network = connman_network_ref(network);
wifi->retries = 0;
return g_supplicant_interface_connect(interface, ssid,
@@ -1338,7 +1520,7 @@ static void disconnect_callback(int result, GSupplicantInterface *interface,
return;
}
- if (wifi->network != NULL) {
+ if (wifi->network) {
/*
* if result < 0 supplican return an error because
* the network is not current.
@@ -1347,14 +1529,14 @@ static void disconnect_callback(int result, GSupplicantInterface *interface,
* disconnect is completed.
*/
if (result < 0)
- connman_network_set_connected(wifi->network, FALSE);
+ connman_network_set_connected(wifi->network, false);
}
wifi->network = NULL;
- wifi->disconnecting = FALSE;
+ wifi->disconnecting = false;
- if (wifi->pending_network != NULL) {
+ if (wifi->pending_network) {
network_connect(wifi->pending_network);
wifi->pending_network = NULL;
}
@@ -1371,20 +1553,20 @@ static int network_disconnect(struct connman_network *network)
DBG("network %p", network);
wifi = connman_device_get_data(device);
- if (wifi == NULL || wifi->interface == NULL)
+ if (!wifi || !wifi->interface)
return -ENODEV;
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
- if (wifi->disconnecting == TRUE)
+ if (wifi->disconnecting)
return -EALREADY;
- wifi->disconnecting = TRUE;
+ wifi->disconnecting = true;
err = g_supplicant_interface_disconnect(wifi->interface,
disconnect_callback, wifi);
if (err < 0)
- wifi->disconnecting = FALSE;
+ wifi->disconnecting = false;
return err;
}
@@ -1412,24 +1594,24 @@ static void interface_added(GSupplicantInterface *interface)
* the interface added signal is sent before the
* interface creation callback is called.
*/
- if (wifi == NULL)
+ if (!wifi)
return;
DBG("ifname %s driver %s wifi %p tethering %d",
ifname, driver, wifi, wifi->tethering);
- if (wifi->device == NULL) {
+ if (!wifi->device) {
connman_error("WiFi device not set");
return;
}
- connman_device_set_powered(wifi->device, TRUE);
+ connman_device_set_powered(wifi->device, true);
- if (wifi->tethering == TRUE)
+ if (wifi->tethering)
return;
}
-static connman_bool_t is_idle(struct wifi_data *wifi)
+static bool is_idle(struct wifi_data *wifi)
{
DBG("state %d", wifi->state);
@@ -1439,7 +1621,7 @@ static connman_bool_t is_idle(struct wifi_data *wifi)
case G_SUPPLICANT_STATE_DISCONNECTED:
case G_SUPPLICANT_STATE_INACTIVE:
case G_SUPPLICANT_STATE_SCANNING:
- return TRUE;
+ return true;
case G_SUPPLICANT_STATE_AUTHENTICATING:
case G_SUPPLICANT_STATE_ASSOCIATING:
@@ -1447,19 +1629,19 @@ static connman_bool_t is_idle(struct wifi_data *wifi)
case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
case G_SUPPLICANT_STATE_COMPLETED:
- return FALSE;
+ return false;
}
- return FALSE;
+ return false;
}
-static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
+static bool is_idle_wps(GSupplicantInterface *interface,
struct wifi_data *wifi)
{
/* First, let's check if WPS processing did not went wrong */
if (g_supplicant_interface_get_wps_state(interface) ==
G_SUPPLICANT_WPS_STATE_FAIL)
- return FALSE;
+ return false;
/* Unlike normal connection, being associated while processing wps
* actually means that we are idling. */
@@ -1470,27 +1652,27 @@ static connman_bool_t is_idle_wps(GSupplicantInterface *interface,
case G_SUPPLICANT_STATE_INACTIVE:
case G_SUPPLICANT_STATE_SCANNING:
case G_SUPPLICANT_STATE_ASSOCIATED:
- return TRUE;
+ return true;
case G_SUPPLICANT_STATE_AUTHENTICATING:
case G_SUPPLICANT_STATE_ASSOCIATING:
case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
case G_SUPPLICANT_STATE_COMPLETED:
- return FALSE;
+ return false;
}
- return FALSE;
+ return false;
}
-static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
+static bool handle_wps_completion(GSupplicantInterface *interface,
struct connman_network *network,
struct connman_device *device,
struct wifi_data *wifi)
{
- connman_bool_t wps;
+ bool wps;
wps = connman_network_get_bool(network, "WiFi.UseWPS");
- if (wps == TRUE) {
+ if (wps) {
const unsigned char *ssid, *wps_ssid;
unsigned int ssid_len, wps_ssid_len;
const char *wps_key;
@@ -1503,12 +1685,12 @@ static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
wps_ssid = g_supplicant_interface_get_wps_ssid(
interface, &wps_ssid_len);
- if (wps_ssid == NULL || wps_ssid_len != ssid_len ||
+ if (!wps_ssid || wps_ssid_len != ssid_len ||
memcmp(ssid, wps_ssid, ssid_len) != 0) {
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
g_supplicant_interface_disconnect(wifi->interface,
disconnect_callback, wifi);
- return FALSE;
+ return false;
}
wps_key = g_supplicant_interface_get_wps_key(interface);
@@ -1518,33 +1700,33 @@ static connman_bool_t handle_wps_completion(GSupplicantInterface *interface,
connman_network_set_string(network, "WiFi.PinWPS", NULL);
}
- return TRUE;
+ return true;
}
-static connman_bool_t handle_4way_handshake_failure(GSupplicantInterface *interface,
+static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
struct connman_network *network,
struct wifi_data *wifi)
{
struct connman_service *service;
if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
- return FALSE;
+ return false;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
- return FALSE;
+ if (!service)
+ return false;
wifi->retries++;
- if (connman_service_get_favorite(service) == TRUE) {
+ if (connman_service_get_favorite(service)) {
if (wifi->retries < FAVORITE_MAXIMUM_RETRIES)
- return TRUE;
- } else if (wifi->retries < MAXIMUM_RETRIES)
- return TRUE;
+ return true;
+ }
+ wifi->retries = 0;
connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
- return FALSE;
+ return false;
}
static void interface_state(GSupplicantInterface *interface)
@@ -1553,19 +1735,27 @@ static void interface_state(GSupplicantInterface *interface)
struct connman_device *device;
struct wifi_data *wifi;
GSupplicantState state = g_supplicant_interface_get_state(interface);
- connman_bool_t wps;
+ bool wps;
wifi = g_supplicant_interface_get_data(interface);
DBG("wifi %p interface state %d", wifi, state);
- if (wifi == NULL)
+ if (!wifi)
return;
- network = wifi->network;
device = wifi->device;
+ if (!device)
+ return;
- if (device == NULL || network == NULL)
+ if (g_supplicant_interface_get_ready(interface) &&
+ !wifi->interface_ready) {
+ wifi->interface_ready = true;
+ finalize_interface_creation(wifi);
+ }
+
+ network = wifi->network;
+ if (!network)
return;
switch (state) {
@@ -1576,8 +1766,8 @@ static void interface_state(GSupplicantInterface *interface)
case G_SUPPLICANT_STATE_ASSOCIATING:
stop_autoscan(device);
- if (wifi->connected == FALSE)
- connman_network_set_associating(network, TRUE);
+ if (!wifi->connected)
+ connman_network_set_associating(network, true);
break;
@@ -1585,11 +1775,10 @@ static void interface_state(GSupplicantInterface *interface)
/* though it should be already stopped: */
stop_autoscan(device);
- if (handle_wps_completion(interface, network, device, wifi) ==
- FALSE)
+ if (!handle_wps_completion(interface, network, device, wifi))
break;
- connman_network_set_connected(network, TRUE);
+ connman_network_set_connected(network, true);
break;
case G_SUPPLICANT_STATE_DISCONNECTED:
@@ -1600,8 +1789,8 @@ static void interface_state(GSupplicantInterface *interface)
* in progress.
*/
wps = connman_network_get_bool(network, "WiFi.UseWPS");
- if (wps == TRUE)
- if (is_idle_wps(interface, wifi) == TRUE)
+ if (wps)
+ if (is_idle_wps(interface, wifi))
break;
if (is_idle(wifi))
@@ -1612,7 +1801,7 @@ static void interface_state(GSupplicantInterface *interface)
* or if we reach the maximum retries we declare the
* psk as wrong */
if (handle_4way_handshake_failure(interface,
- network, wifi) == TRUE)
+ network, wifi))
break;
/* We disable the selected network, if not then
@@ -1621,16 +1810,16 @@ static void interface_state(GSupplicantInterface *interface)
FALSE) != 0)
DBG("Could not disables selected network");
- connman_network_set_connected(network, FALSE);
- connman_network_set_associating(network, FALSE);
- wifi->disconnecting = FALSE;
+ connman_network_set_connected(network, false);
+ connman_network_set_associating(network, false);
+ wifi->disconnecting = false;
start_autoscan(device);
break;
case G_SUPPLICANT_STATE_INACTIVE:
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
start_autoscan(device);
break;
@@ -1659,17 +1848,17 @@ static void interface_state(GSupplicantInterface *interface)
case G_SUPPLICANT_STATE_ASSOCIATED:
case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
- if (wifi->connected == TRUE)
+ if (wifi->connected)
connman_warn("Probably roaming right now!"
" Staying connected...");
else
- wifi->connected = FALSE;
+ wifi->connected = false;
break;
case G_SUPPLICANT_STATE_COMPLETED:
- wifi->connected = TRUE;
+ wifi->connected = true;
break;
default:
- wifi->connected = FALSE;
+ wifi->connected = false;
break;
}
@@ -1685,16 +1874,29 @@ static void interface_removed(GSupplicantInterface *interface)
wifi = g_supplicant_interface_get_data(interface);
- if (wifi != NULL && wifi->tethering == TRUE)
+ if (wifi && wifi->tethering)
return;
- if (wifi == NULL || wifi->device == NULL) {
+ if (!wifi || !wifi->device) {
DBG("wifi interface already removed");
return;
}
wifi->interface = NULL;
- connman_device_set_powered(wifi->device, FALSE);
+ connman_device_set_powered(wifi->device, false);
+
+ check_p2p_technology();
+}
+
+static void p2p_support(GSupplicantInterface *interface)
+{
+ DBG("");
+
+ if (!g_supplicant_interface_has_p2p(interface))
+ return;
+
+ if (connman_technology_driver_register(&p2p_tech_driver) == 0)
+ DBG("Could not register P2P technology driver");
}
static void scan_started(GSupplicantInterface *interface)
@@ -1726,17 +1928,22 @@ static void network_added(GSupplicantNetwork *supplicant_network)
const char *name, *identifier, *security, *group, *mode;
const unsigned char *ssid;
unsigned int ssid_len;
- connman_bool_t wps;
- connman_bool_t wps_pbc;
- connman_bool_t wps_ready;
- connman_bool_t wps_advertizing;
+ bool wps;
+ bool wps_pbc;
+ bool wps_ready;
+ bool wps_advertizing;
- DBG("");
+ mode = g_supplicant_network_get_mode(supplicant_network);
+ identifier = g_supplicant_network_get_identifier(supplicant_network);
+
+ DBG("%s", identifier);
+
+ if (!g_strcmp0(mode, "adhoc"))
+ return;
interface = g_supplicant_network_get_interface(supplicant_network);
wifi = g_supplicant_interface_get_data(interface);
name = g_supplicant_network_get_name(supplicant_network);
- identifier = g_supplicant_network_get_identifier(supplicant_network);
security = g_supplicant_network_get_security(supplicant_network);
group = g_supplicant_network_get_identifier(supplicant_network);
wps = g_supplicant_network_get_wps(supplicant_network);
@@ -1744,19 +1951,18 @@ static void network_added(GSupplicantNetwork *supplicant_network)
wps_ready = g_supplicant_network_is_wps_active(supplicant_network);
wps_advertizing = g_supplicant_network_is_wps_advertizing(
supplicant_network);
- mode = g_supplicant_network_get_mode(supplicant_network);
- if (wifi == NULL)
+ if (!wifi)
return;
ssid = g_supplicant_network_get_ssid(supplicant_network, &ssid_len);
network = connman_device_get_network(wifi->device, identifier);
- if (network == NULL) {
+ if (!network) {
network = connman_network_create(identifier,
CONNMAN_NETWORK_TYPE_WIFI);
- if (network == NULL)
+ if (!network)
return;
connman_network_set_index(network, wifi->index);
@@ -1769,7 +1975,7 @@ static void network_added(GSupplicantNetwork *supplicant_network)
wifi->networks = g_slist_prepend(wifi->networks, network);
}
- if (name != NULL && name[0] != '\0')
+ if (name && name[0] != '\0')
connman_network_set_name(network, name);
connman_network_set_blob(network, "WiFi.SSID",
@@ -1779,27 +1985,27 @@ static void network_added(GSupplicantNetwork *supplicant_network)
calculate_strength(supplicant_network));
connman_network_set_bool(network, "WiFi.WPS", wps);
- if (wps == TRUE) {
+ if (wps) {
/* Is AP advertizing for WPS association?
* If so, we decide to use WPS by default */
- if (wps_ready == TRUE && wps_pbc == TRUE &&
- wps_advertizing == TRUE)
- connman_network_set_bool(network, "WiFi.UseWPS", TRUE);
+ if (wps_ready && wps_pbc &&
+ wps_advertizing)
+ connman_network_set_bool(network, "WiFi.UseWPS", true);
}
connman_network_set_frequency(network,
g_supplicant_network_get_frequency(supplicant_network));
- connman_network_set_available(network, TRUE);
+ connman_network_set_available(network, true);
connman_network_set_string(network, "WiFi.Mode", mode);
- if (ssid != NULL)
+ if (ssid)
connman_network_set_group(network, group);
- if (wifi->hidden != NULL && ssid != NULL) {
- if (wifi->hidden->ssid_len == ssid_len &&
- memcmp(wifi->hidden->ssid, ssid,
- ssid_len) == 0) {
+ if (wifi->hidden && ssid) {
+ if (!g_strcmp0(wifi->hidden->security, security) &&
+ wifi->hidden->ssid_len == ssid_len &&
+ !memcmp(wifi->hidden->ssid, ssid, ssid_len)) {
connman_network_connect_hidden(network,
wifi->hidden->identity,
wifi->hidden->passphrase,
@@ -1825,11 +2031,11 @@ static void network_removed(GSupplicantNetwork *network)
DBG("name %s", name);
- if (wifi == NULL)
+ if (!wifi)
return;
connman_network = connman_device_get_network(wifi->device, identifier);
- if (connman_network == NULL)
+ if (!connman_network)
return;
wifi->networks = g_slist_remove(wifi->networks, connman_network);
@@ -1852,20 +2058,54 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
DBG("name %s", name);
- if (wifi == NULL)
+ if (!wifi)
return;
connman_network = connman_device_get_network(wifi->device, identifier);
- if (connman_network == NULL)
+ if (!connman_network)
return;
- if (g_str_equal(property, "Signal") == TRUE) {
+ if (g_str_equal(property, "Signal")) {
connman_network_set_strength(connman_network,
calculate_strength(network));
connman_network_update(connman_network);
}
}
+static void peer_found(GSupplicantPeer *peer)
+{
+ struct connman_peer *connman_peer;
+ const char *identifier, *name;
+
+ identifier = g_supplicant_peer_get_identifier(peer);
+ name = g_supplicant_peer_get_name(peer);
+
+ DBG("ident: %s", identifier);
+
+ connman_peer = connman_peer_get(identifier);
+ if (connman_peer)
+ return;
+
+ connman_peer = connman_peer_create(identifier);
+ connman_peer_set_name(connman_peer, name);
+
+ connman_peer_register(connman_peer);
+}
+
+static void peer_lost(GSupplicantPeer *peer)
+{
+ struct connman_peer *connman_peer;
+ const char *identifier;
+
+ identifier = g_supplicant_peer_get_identifier(peer);
+
+ DBG("ident: %s", identifier);
+
+ connman_peer = connman_peer_get(identifier);
+ if (connman_peer)
+ connman_peer_unregister(connman_peer);
+}
+
static void debug(const char *str)
{
if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
@@ -1878,11 +2118,14 @@ static const GSupplicantCallbacks callbacks = {
.interface_added = interface_added,
.interface_state = interface_state,
.interface_removed = interface_removed,
+ .p2p_support = p2p_support,
.scan_started = scan_started,
.scan_finished = scan_finished,
.network_added = network_added,
.network_removed = network_removed,
.network_changed = network_changed,
+ .peer_found = peer_found,
+ .peer_lost = peer_lost,
.debug = debug,
};
@@ -1911,7 +2154,7 @@ static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
GSupplicantSSID *ap;
ap = g_try_malloc0(sizeof(GSupplicantSSID));
- if (ap == NULL)
+ if (!ap)
return NULL;
ap->mode = G_SUPPLICANT_MODE_MASTER;
@@ -1920,7 +2163,7 @@ static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
ap->scan_ssid = 0;
ap->freq = 2412;
- if (passphrase == NULL || strlen(passphrase) == 0) {
+ if (!passphrase || strlen(passphrase) == 0) {
ap->security = G_SUPPLICANT_SECURITY_NONE;
ap->passphrase = NULL;
} else {
@@ -1945,7 +2188,7 @@ static void ap_start_callback(int result, GSupplicantInterface *interface,
if (result < 0) {
connman_inet_remove_from_bridge(info->wifi->index,
info->wifi->bridge);
- connman_technology_tethering_notify(info->technology, FALSE);
+ connman_technology_tethering_notify(info->technology, false);
}
g_free(info->ifname);
@@ -1964,9 +2207,10 @@ static void ap_create_callback(int result,
if (result < 0) {
connman_inet_remove_from_bridge(info->wifi->index,
info->wifi->bridge);
- connman_technology_tethering_notify(info->technology, FALSE);
+ connman_technology_tethering_notify(info->technology, false);
g_free(info->ifname);
+ g_free(info->ssid);
g_free(info);
return;
}
@@ -1991,16 +2235,17 @@ static void sta_remove_callback(int result,
DBG("ifname %s result %d ", info->ifname, result);
if (result < 0) {
- info->wifi->tethering = TRUE;
+ info->wifi->tethering = true;
g_free(info->ifname);
+ g_free(info->ssid);
g_free(info);
return;
}
info->wifi->interface = NULL;
- connman_technology_tethering_notify(info->technology, TRUE);
+ connman_technology_tethering_notify(info->technology, true);
g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
ap_create_callback,
@@ -2009,7 +2254,7 @@ static void sta_remove_callback(int result,
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)
{
GList *list;
GSupplicantInterface *interface;
@@ -2021,20 +2266,20 @@ static int tech_set_tethering(struct connman_technology *technology,
DBG("");
- if (enabled == FALSE) {
+ if (!enabled) {
for (list = iface_list; list; list = list->next) {
wifi = list->data;
- if (wifi->tethering == TRUE) {
- wifi->tethering = FALSE;
+ if (wifi->tethering) {
+ wifi->tethering = false;
connman_inet_remove_from_bridge(wifi->index,
bridge);
- wifi->bridged = FALSE;
+ wifi->bridged = false;
}
}
- connman_technology_tethering_notify(technology, FALSE);
+ connman_technology_tethering_notify(technology, false);
return 0;
}
@@ -2044,7 +2289,7 @@ static int tech_set_tethering(struct connman_technology *technology,
interface = wifi->interface;
- if (interface == NULL)
+ if (!interface)
continue;
ifname = g_supplicant_interface_get_ifname(wifi->interface);
@@ -2056,24 +2301,25 @@ static int tech_set_tethering(struct connman_technology *technology,
}
info = g_try_malloc0(sizeof(struct wifi_tethering_info));
- if (info == NULL)
+ if (!info)
return -ENOMEM;
info->wifi = wifi;
info->technology = technology;
info->wifi->bridge = bridge;
info->ssid = ssid_ap_init(identifier, passphrase);
- if (info->ssid == NULL) {
+ if (!info->ssid) {
g_free(info);
continue;
}
info->ifname = g_strdup(ifname);
- if (info->ifname == NULL) {
+ if (!info->ifname) {
+ g_free(info->ssid);
g_free(info);
continue;
}
- info->wifi->tethering = TRUE;
+ info->wifi->tethering = true;
err = g_supplicant_interface_remove(interface,
sta_remove_callback,
@@ -2089,7 +2335,7 @@ static void regdom_callback(int result, const char *alpha2, void *user_data)
{
DBG("");
- if (wifi_technology == NULL)
+ if (!wifi_technology)
return;
if (result != 0)