summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c313
1 files changed, 148 insertions, 165 deletions
diff --git a/src/device.c b/src/device.c
index 5feeee1..a97d790 100644
--- a/src/device.c
+++ b/src/device.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,18 +48,18 @@ struct connman_device {
int refcount;
enum connman_device_type type;
enum connman_pending_type powered_pending; /* Indicates a pending
- enable/disable request */
- connman_bool_t powered;
- connman_bool_t scanning;
- connman_bool_t disconnected;
- connman_bool_t reconnect;
+ * enable/disable
+ * request
+ */
+ bool powered;
+ bool scanning;
+ bool disconnected;
char *name;
char *node;
char *address;
char *interface;
char *ident;
char *path;
- char *devname;
int index;
guint pending_timeout;
@@ -127,7 +127,8 @@ static const char *type2string(enum connman_device_type type)
return NULL;
}
-enum connman_service_type __connman_device_get_service_type(struct connman_device *device)
+enum connman_service_type __connman_device_get_service_type(
+ struct connman_device *device)
{
enum connman_device_type type = connman_device_get_type(device);
@@ -181,7 +182,7 @@ int __connman_device_enable(struct connman_device *device)
if (device->powered_pending == PENDING_ENABLE)
return -EALREADY;
- if (device->powered_pending == PENDING_NONE && device->powered == TRUE)
+ if (device->powered_pending == PENDING_NONE && device->powered)
return -EALREADY;
device->powered_pending = PENDING_ENABLE;
@@ -192,13 +193,13 @@ int __connman_device_enable(struct connman_device *device)
* Invoke the callback
*/
if (err == 0) {
- connman_device_set_powered(device, TRUE);
+ connman_device_set_powered(device, true);
goto done;
}
if (err == -EALREADY) {
/* If device is already powered, but connman is not updated */
- connman_device_set_powered(device, TRUE);
+ connman_device_set_powered(device, true);
goto done;
}
/*
@@ -219,9 +220,6 @@ int __connman_device_disable(struct connman_device *device)
DBG("device %p", device);
- if (!device->driver || !device->driver->disable)
- return -EOPNOTSUPP;
-
/* Ongoing power enable request */
if (device->powered_pending == PENDING_ENABLE)
return -EBUSY;
@@ -229,25 +227,27 @@ int __connman_device_disable(struct connman_device *device)
if (device->powered_pending == PENDING_DISABLE)
return -EALREADY;
- if (device->powered_pending == PENDING_NONE && device->powered == FALSE)
+ if (device->powered_pending == PENDING_NONE && !device->powered)
return -EALREADY;
device->powered_pending = PENDING_DISABLE;
- device->reconnect = FALSE;
if (device->network) {
struct connman_service *service =
connman_service_lookup_from_network(device->network);
- if (service != NULL)
+ if (service)
__connman_service_disconnect(service);
else
- connman_network_set_connected(device->network, FALSE);
+ connman_network_set_connected(device->network, false);
}
+ if (!device->driver || !device->driver->disable)
+ return -EOPNOTSUPP;
+
err = device->driver->disable(device);
if (err == 0 || err == -EALREADY) {
- connman_device_set_powered(device, FALSE);
+ connman_device_set_powered(device, false);
goto done;
}
@@ -264,10 +264,10 @@ static void probe_driver(struct connman_device_driver *driver)
DBG("driver %p name %s", driver, driver->name);
- for (list = device_list; list != NULL; list = list->next) {
+ for (list = device_list; list; list = list->next) {
struct connman_device *device = list->data;
- if (device->driver != NULL)
+ if (device->driver)
continue;
if (driver->type != device->type)
@@ -302,7 +302,7 @@ static void remove_driver(struct connman_device_driver *driver)
DBG("driver %p name %s", driver, driver->name);
- for (list = device_list; list != NULL; list = list->next) {
+ for (list = device_list; list; list = list->next) {
struct connman_device *device = list->data;
if (device->driver == driver)
@@ -310,12 +310,12 @@ static void remove_driver(struct connman_device_driver *driver)
}
}
-connman_bool_t __connman_device_has_driver(struct connman_device *device)
+bool __connman_device_has_driver(struct connman_device *device)
{
- if (device == NULL || device->driver == NULL)
- return FALSE;
+ if (!device || !device->driver)
+ return false;
- return TRUE;
+ return true;
}
static GSList *driver_list = NULL;
@@ -385,7 +385,6 @@ static void device_destruct(struct connman_device *device)
g_free(device->address);
g_free(device->interface);
g_free(device->path);
- g_free(device->devname);
g_free(device->last_network);
@@ -412,7 +411,7 @@ struct connman_device *connman_device_create(const char *node,
DBG("node %s type %d", node, type);
device = g_try_new0(struct connman_device, 1);
- if (device == NULL)
+ if (!device)
return NULL;
DBG("device %p", device);
@@ -521,15 +520,12 @@ int connman_device_get_index(struct connman_device *device)
void connman_device_set_interface(struct connman_device *device,
const char *interface)
{
- g_free(device->devname);
- device->devname = g_strdup(interface);
-
g_free(device->interface);
device->interface = g_strdup(interface);
- if (device->name == NULL) {
+ if (!device->name) {
const char *str = type2description(device->type);
- if (str != NULL && device->interface != NULL)
+ if (str && device->interface)
device->name = g_strdup_printf("%s (%s)", str,
device->interface);
}
@@ -562,7 +558,7 @@ const char *connman_device_get_ident(struct connman_device *device)
* Change power state of device
*/
int connman_device_set_powered(struct connman_device *device,
- connman_bool_t powered)
+ bool powered)
{
enum connman_service_type type;
@@ -579,36 +575,39 @@ int connman_device_set_powered(struct connman_device *device,
type = __connman_device_get_service_type(device);
- if (device->powered == FALSE) {
+ if (!device->powered) {
__connman_technology_disabled(type);
return 0;
}
__connman_technology_enabled(type);
- connman_device_set_disconnected(device, FALSE);
- device->scanning = FALSE;
+ connman_device_set_disconnected(device, false);
+ device->scanning = false;
if (device->driver && device->driver->scan)
- device->driver->scan(device, NULL, 0, NULL, NULL, NULL);
+ device->driver->scan(CONNMAN_SERVICE_TYPE_UNKNOWN, device,
+ NULL, 0, NULL, NULL, NULL, NULL);
return 0;
}
-connman_bool_t connman_device_get_powered(struct connman_device *device)
+bool connman_device_get_powered(struct connman_device *device)
{
return device->powered;
}
-static int device_scan(struct connman_device *device)
+static int device_scan(enum connman_service_type type,
+ struct connman_device *device)
{
if (!device->driver || !device->driver->scan)
return -EOPNOTSUPP;
- if (device->powered == FALSE)
+ if (!device->powered)
return -ENOLINK;
- return device->driver->scan(device, NULL, 0, NULL, NULL, NULL);
+ return device->driver->scan(type, device, NULL, 0,
+ NULL, NULL, NULL, NULL);
}
int __connman_device_disconnect(struct connman_device *device)
@@ -618,14 +617,14 @@ int __connman_device_disconnect(struct connman_device *device)
DBG("device %p", device);
- connman_device_set_disconnected(device, TRUE);
+ connman_device_set_disconnected(device, true);
g_hash_table_iter_init(&iter, device->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_connecting(network) == TRUE) {
+ if (connman_network_get_connecting(network)) {
/*
* Skip network in the process of connecting.
* This is a workaround for WiFi networks serviced
@@ -647,32 +646,11 @@ int __connman_device_disconnect(struct connman_device *device)
return 0;
}
-int connman_device_disconnect_service(struct connman_device *device)
-{
- DBG("device %p", device);
-
- device->reconnect = FALSE;
-
- if (device->network) {
- struct connman_service *service =
- connman_service_lookup_from_network(device->network);
-
- if (service != NULL)
- __connman_service_disconnect(service);
- else
- connman_network_set_connected(device->network, FALSE);
- }
-
- return 0;
-}
-
int connman_device_reconnect_service(struct connman_device *device)
{
DBG("device %p", device);
- device->reconnect = TRUE;
-
- __connman_service_auto_connect();
+ __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
return 0;
}
@@ -682,7 +660,7 @@ static void mark_network_available(gpointer key, gpointer value,
{
struct connman_network *network = value;
- connman_network_set_available(network, TRUE);
+ connman_network_set_available(network, true);
}
static void mark_network_unavailable(gpointer key, gpointer value,
@@ -690,11 +668,11 @@ static void mark_network_unavailable(gpointer key, gpointer value,
{
struct connman_network *network = value;
- if (connman_network_get_connected(network) == TRUE ||
- connman_network_get_connecting(network) == TRUE)
+ if (connman_network_get_connected(network) ||
+ connman_network_get_connecting(network))
return;
- connman_network_set_available(network, FALSE);
+ connman_network_set_available(network, false);
}
static gboolean remove_unavailable_network(gpointer key, gpointer value,
@@ -702,10 +680,10 @@ static gboolean remove_unavailable_network(gpointer key, gpointer value,
{
struct connman_network *network = value;
- if (connman_network_get_connected(network) == TRUE)
+ if (connman_network_get_connected(network))
return FALSE;
- if (connman_network_get_available(network) == TRUE)
+ if (connman_network_get_available(network))
return FALSE;
return TRUE;
@@ -717,7 +695,7 @@ void __connman_device_cleanup_networks(struct connman_device *device)
remove_unavailable_network, NULL);
}
-connman_bool_t connman_device_get_scanning(struct connman_device *device)
+bool connman_device_get_scanning(struct connman_device *device)
{
return device->scanning;
}
@@ -736,7 +714,7 @@ void connman_device_reset_scanning(struct connman_device *device)
* Change scanning state of device
*/
int connman_device_set_scanning(struct connman_device *device,
- connman_bool_t scanning)
+ enum connman_service_type type, bool scanning)
{
DBG("device %p scanning %d", device, scanning);
@@ -748,7 +726,7 @@ int connman_device_set_scanning(struct connman_device *device,
device->scanning = scanning;
- if (scanning == TRUE) {
+ if (scanning) {
__connman_technology_scan_started(device);
g_hash_table_foreach(device->networks,
@@ -759,9 +737,9 @@ int connman_device_set_scanning(struct connman_device *device,
__connman_device_cleanup_networks(device);
- __connman_technology_scan_stopped(device);
+ __connman_technology_scan_stopped(device, type);
- __connman_service_auto_connect();
+ __connman_service_auto_connect(CONNMAN_SERVICE_CONNECT_REASON_AUTO);
return 0;
}
@@ -774,7 +752,7 @@ int connman_device_set_scanning(struct connman_device *device,
* Change disconnected state of device (only for device with networks)
*/
int connman_device_set_disconnected(struct connman_device *device,
- connman_bool_t disconnected)
+ bool disconnected)
{
DBG("device %p disconnected %d", device, disconnected);
@@ -792,7 +770,7 @@ int connman_device_set_disconnected(struct connman_device *device,
*
* Get device disconnected state
*/
-connman_bool_t connman_device_get_disconnected(struct connman_device *device)
+bool connman_device_get_disconnected(struct connman_device *device)
{
return device->disconnected;
}
@@ -810,16 +788,16 @@ int connman_device_set_string(struct connman_device *device,
{
DBG("device %p key %s value %s", device, key, value);
- if (g_str_equal(key, "Address") == TRUE) {
+ if (g_str_equal(key, "Address")) {
g_free(device->address);
device->address = g_strdup(value);
- } else if (g_str_equal(key, "Name") == TRUE) {
+ } else if (g_str_equal(key, "Name")) {
g_free(device->name);
device->name = g_strdup(value);
- } else if (g_str_equal(key, "Node") == TRUE) {
+ } else if (g_str_equal(key, "Node")) {
g_free(device->node);
device->node = g_strdup(value);
- } else if (g_str_equal(key, "Path") == TRUE) {
+ } else if (g_str_equal(key, "Path")) {
g_free(device->path);
device->path = g_strdup(value);
} else {
@@ -841,15 +819,15 @@ const char *connman_device_get_string(struct connman_device *device,
{
DBG("device %p key %s", device, key);
- if (g_str_equal(key, "Address") == TRUE)
+ if (g_str_equal(key, "Address"))
return device->address;
- else if (g_str_equal(key, "Name") == TRUE)
+ else if (g_str_equal(key, "Name"))
return device->name;
- else if (g_str_equal(key, "Node") == TRUE)
+ else if (g_str_equal(key, "Node"))
return device->node;
- else if (g_str_equal(key, "Interface") == TRUE)
+ else if (g_str_equal(key, "Interface"))
return device->interface;
- else if (g_str_equal(key, "Path") == TRUE)
+ else if (g_str_equal(key, "Path"))
return device->path;
return NULL;
@@ -869,7 +847,7 @@ int connman_device_add_network(struct connman_device *device,
DBG("device %p network %p", device, network);
- if (identifier == NULL)
+ if (!identifier)
return -EINVAL;
connman_network_ref(network);
@@ -911,7 +889,7 @@ int connman_device_remove_network(struct connman_device *device,
DBG("device %p network %p", device, network);
- if (network == NULL)
+ if (!network)
return 0;
identifier = connman_network_get_identifier(network);
@@ -920,23 +898,18 @@ int connman_device_remove_network(struct connman_device *device,
return 0;
}
-void connman_device_remove_all_networks(struct connman_device *device)
-{
- g_hash_table_remove_all(device->networks);
-}
-
void __connman_device_set_network(struct connman_device *device,
struct connman_network *network)
{
const char *name;
- if (device == NULL)
+ if (!device)
return;
if (device->network == network)
return;
- if (network != NULL) {
+ if (network) {
name = connman_network_get_string(network, "Name");
g_free(device->last_network);
device->last_network = g_strdup(name);
@@ -950,26 +923,14 @@ void __connman_device_set_network(struct connman_device *device,
}
}
-void __connman_device_set_reconnect(struct connman_device *device,
- connman_bool_t reconnect)
-{
- device->reconnect = reconnect;
-}
-
-connman_bool_t __connman_device_get_reconnect(
- struct connman_device *device)
-{
- return device->reconnect;
-}
-
-static gboolean match_driver(struct connman_device *device,
+static bool match_driver(struct connman_device *device,
struct connman_device_driver *driver)
{
if (device->type == driver->type ||
driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
/**
@@ -984,13 +945,13 @@ int connman_device_register(struct connman_device *device)
DBG("device %p name %s", device, device->name);
- if (device->driver != NULL)
+ if (device->driver)
return -EALREADY;
for (list = driver_list; list; list = list->next) {
struct connman_device_driver *driver = list->data;
- if (match_driver(device, driver) == FALSE)
+ if (!match_driver(device, driver))
continue;
DBG("driver %p name %s", driver, driver->name);
@@ -1001,7 +962,7 @@ int connman_device_register(struct connman_device *device)
}
}
- if (device->driver == NULL)
+ if (!device->driver)
return 0;
return __connman_technology_add_device(device);
@@ -1017,7 +978,7 @@ void connman_device_unregister(struct connman_device *device)
{
DBG("device %p name %s", device, device->name);
- if (device->driver == NULL)
+ if (!device->driver)
return;
remove_device(device);
@@ -1051,7 +1012,7 @@ struct connman_device *__connman_device_find_device(
{
GSList *list;
- for (list = device_list; list != NULL; list = list->next) {
+ for (list = device_list; list; list = list->next) {
struct connman_device *device = list->data;
enum connman_service_type service_type =
__connman_device_get_service_type(device);
@@ -1069,7 +1030,7 @@ struct connman_device *connman_device_find_by_index(int index)
{
GSList *list;
- for (list = device_list; list != NULL; list = list->next) {
+ for (list = device_list; list; list = list->next) {
struct connman_device *device = list->data;
if (device->index == index)
return device;
@@ -1088,10 +1049,10 @@ struct connman_device *connman_device_find_by_index(int index)
int connman_device_set_regdom(struct connman_device *device,
const char *alpha2)
{
- if (device->driver == NULL || device->driver->set_regdom == NULL)
+ if (!device->driver || !device->driver->set_regdom)
return -ENOTSUP;
- if (device->powered == FALSE)
+ if (!device->powered)
return -EINVAL;
return device->driver->set_regdom(device, alpha2);
@@ -1112,7 +1073,7 @@ void connman_device_regdom_notify(struct connman_device *device,
int __connman_device_request_scan(enum connman_service_type type)
{
- connman_bool_t success = FALSE;
+ bool success = false;
int last_err = -ENOSYS;
GSList *list;
int err;
@@ -1128,29 +1089,33 @@ int __connman_device_request_scan(enum connman_service_type type)
case CONNMAN_SERVICE_TYPE_GADGET:
return -EOPNOTSUPP;
case CONNMAN_SERVICE_TYPE_WIFI:
+ case CONNMAN_SERVICE_TYPE_P2P:
break;
}
- for (list = device_list; list != NULL; list = list->next) {
+ for (list = device_list; list; list = list->next) {
struct connman_device *device = list->data;
enum connman_service_type service_type =
__connman_device_get_service_type(device);
- if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
- service_type != type) {
- continue;
+ if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN) {
+ if (type == CONNMAN_SERVICE_TYPE_P2P) {
+ if (service_type != CONNMAN_SERVICE_TYPE_WIFI)
+ continue;
+ } else if (service_type != type)
+ continue;
}
- err = device_scan(device);
+ err = device_scan(type, device);
if (err == 0 || err == -EALREADY || err == -EINPROGRESS) {
- success = TRUE;
+ success = true;
} else {
last_err = err;
DBG("device %p err %d", device, err);
}
}
- if (success == TRUE)
+ if (success)
return 0;
return last_err;
@@ -1159,19 +1124,17 @@ int __connman_device_request_scan(enum connman_service_type type)
int __connman_device_request_hidden_scan(struct connman_device *device,
const char *ssid, unsigned int ssid_len,
const char *identity, const char *passphrase,
- void *user_data)
+ const char *security, void *user_data)
{
DBG("device %p", device);
- if (device == NULL || device->driver == NULL ||
- device->driver->scan == NULL)
+ if (!device || !device->driver ||
+ !device->driver->scan)
return -EINVAL;
- if (device->scanning == TRUE)
- return -EALREADY;
-
- return device->driver->scan(device, ssid, ssid_len,
- identity, passphrase, user_data);
+ return device->driver->scan(CONNMAN_SERVICE_TYPE_UNKNOWN,
+ device, ssid, ssid_len, identity,
+ passphrase, security, user_data);
}
static char *index2ident(int index, const char *prefix)
@@ -1274,10 +1237,10 @@ struct connman_device *connman_device_create_from_index(int index)
return NULL;
devname = connman_inet_ifname(index);
- if (devname == NULL)
+ if (!devname)
return NULL;
- if (__connman_device_isfiltered(devname) == TRUE) {
+ if (__connman_device_isfiltered(devname)) {
connman_info("Ignoring interface %s (filtered)", devname);
g_free(devname);
return NULL;
@@ -1305,7 +1268,7 @@ struct connman_device *connman_device_create_from_index(int index)
}
device = connman_device_create(name, type);
- if (device == NULL)
+ if (!device)
goto done;
switch (type) {
@@ -1330,7 +1293,7 @@ struct connman_device *connman_device_create_from_index(int index)
connman_device_set_index(device, index);
connman_device_set_interface(device, devname);
- if (ident != NULL) {
+ if (ident) {
connman_device_set_ident(device, ident);
g_free(ident);
}
@@ -1345,57 +1308,57 @@ done:
return device;
}
-connman_bool_t __connman_device_isfiltered(const char *devname)
+bool __connman_device_isfiltered(const char *devname)
{
char **pattern;
char **blacklisted_interfaces;
- gboolean match;
+ bool match;
- if (device_filter == NULL)
+ if (!device_filter)
goto nodevice;
- for (pattern = device_filter, match = FALSE; *pattern; pattern++) {
- if (g_pattern_match_simple(*pattern, devname) == TRUE) {
- match = TRUE;
+ for (pattern = device_filter, match = false; *pattern; pattern++) {
+ if (g_pattern_match_simple(*pattern, devname)) {
+ match = true;
break;
}
}
- if (match == FALSE) {
+ if (!match) {
DBG("ignoring device %s (match)", devname);
- return TRUE;
+ return true;
}
nodevice:
- if (g_pattern_match_simple("dummy*", devname) == TRUE) {
+ if (g_pattern_match_simple("dummy*", devname)) {
DBG("ignoring dummy networking devices");
- return TRUE;
+ return true;
}
- if (nodevice_filter == NULL)
+ if (!nodevice_filter)
goto list;
for (pattern = nodevice_filter; *pattern; pattern++) {
- if (g_pattern_match_simple(*pattern, devname) == TRUE) {
+ if (g_pattern_match_simple(*pattern, devname)) {
DBG("ignoring device %s (no match)", devname);
- return TRUE;
+ return true;
}
}
list:
blacklisted_interfaces =
connman_setting_get_string_list("NetworkInterfaceBlacklist");
- if (blacklisted_interfaces == NULL)
- return FALSE;
+ if (!blacklisted_interfaces)
+ return false;
for (pattern = blacklisted_interfaces; *pattern; pattern++) {
- if (g_str_has_prefix(devname, *pattern) == TRUE) {
+ if (g_str_has_prefix(devname, *pattern)) {
DBG("ignoring device %s (blacklist)", devname);
- return TRUE;
+ return true;
}
}
- return FALSE;
+ return false;
}
static void cleanup_devices(void)
@@ -1418,21 +1381,41 @@ static void cleanup_devices(void)
interfaces = __connman_inet_get_running_interfaces();
- if (interfaces == NULL)
+ if (!interfaces)
return;
- for (i = 0; interfaces[i] != NULL; i++) {
- connman_bool_t filtered;
+ for (i = 0; interfaces[i]; i++) {
+ bool filtered;
int index;
+ struct sockaddr_in sin_addr, sin_mask;
filtered = __connman_device_isfiltered(interfaces[i]);
- if (filtered == TRUE)
+ if (filtered)
continue;
index = connman_inet_ifindex(interfaces[i]);
if (index < 0)
continue;
+ if (!__connman_inet_get_address_netmask(index, &sin_addr,
+ &sin_mask)) {
+ char *address = g_strdup(inet_ntoa(sin_addr.sin_addr));
+ char *netmask = g_strdup(inet_ntoa(sin_mask.sin_addr));
+
+ if (__connman_config_address_provisioned(address,
+ netmask)) {
+ DBG("Skip %s which is already provisioned "
+ "with %s/%s", interfaces[i], address,
+ netmask);
+ g_free(address);
+ g_free(netmask);
+ continue;
+ }
+
+ g_free(address);
+ g_free(netmask);
+ }
+
DBG("cleaning up %s index %d", interfaces[i], index);
connman_inet_ifdown(index);
@@ -1450,10 +1433,10 @@ int __connman_device_init(const char *device, const char *nodevice)
{
DBG("");
- if (device != NULL)
+ if (device)
device_filter = g_strsplit(device, ",", -1);
- if (nodevice != NULL)
+ if (nodevice)
nodevice_filter = g_strsplit(nodevice, ",", -1);
cleanup_devices();