summaryrefslogtreecommitdiff
path: root/src/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network.c')
-rw-r--r--src/network.c499
1 files changed, 261 insertions, 238 deletions
diff --git a/src/network.c b/src/network.c
index 6a926cbc..160bd061 100644
--- a/src/network.c
+++ b/src/network.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
@@ -47,9 +47,9 @@ static GSList *driver_list = NULL;
struct connman_network {
int refcount;
enum connman_network_type type;
- connman_bool_t available;
- connman_bool_t connected;
- connman_bool_t roaming;
+ bool available;
+ bool connected;
+ bool roaming;
uint8_t strength;
uint16_t frequency;
char *identifier;
@@ -64,8 +64,8 @@ struct connman_network {
struct connman_network_driver *driver;
void *driver_data;
- connman_bool_t connecting;
- connman_bool_t associating;
+ bool connecting;
+ bool associating;
struct connman_device *device;
@@ -76,7 +76,6 @@ struct connman_network {
unsigned short channel;
char *security;
char *passphrase;
- char *agent_passphrase;
char *eap;
char *identity;
char *agent_identity;
@@ -85,8 +84,8 @@ struct connman_network {
char *private_key_path;
char *private_key_passphrase;
char *phase2_auth;
- connman_bool_t wps;
- connman_bool_t use_wps;
+ bool wps;
+ bool use_wps;
char *pin_wps;
} wifi;
@@ -100,6 +99,8 @@ static const char *type2string(enum connman_network_type type)
break;
case CONNMAN_NETWORK_TYPE_ETHERNET:
return "ethernet";
+ case CONNMAN_NETWORK_TYPE_GADGET:
+ return "gadget";
case CONNMAN_NETWORK_TYPE_WIFI:
return "wifi";
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
@@ -112,14 +113,14 @@ static const char *type2string(enum connman_network_type type)
return NULL;
}
-static gboolean match_driver(struct connman_network *network,
+static bool match_driver(struct connman_network *network,
struct connman_network_driver *driver)
{
if (network->type == driver->type ||
driver->type == CONNMAN_NETWORK_TYPE_UNKNOWN)
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
static void set_configuration(struct connman_network *network,
@@ -129,12 +130,12 @@ static void set_configuration(struct connman_network *network,
DBG("network %p", network);
- if (network->device == NULL)
+ if (!network->device)
return;
__connman_device_set_network(network->device, network);
- connman_device_set_disconnected(network->device, FALSE);
+ connman_device_set_disconnected(network->device, false);
service = connman_service_lookup_from_network(network);
__connman_service_ipconfig_indicate_state(service,
@@ -149,14 +150,20 @@ static void dhcp_success(struct connman_network *network)
int err;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
goto err;
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
- network->connecting = FALSE;
+ network->connecting = false;
ipconfig_ipv4 = __connman_service_get_ip4config(service);
+
+ DBG("lease acquired for ipconfig %p", ipconfig_ipv4);
+
+ if (!ipconfig_ipv4)
+ return;
+
err = __connman_ipconfig_address_add(ipconfig_ipv4);
if (err < 0)
goto err;
@@ -175,22 +182,30 @@ err:
static void dhcp_failure(struct connman_network *network)
{
struct connman_service *service;
+ struct connman_ipconfig *ipconfig_ipv4;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return;
- __connman_service_ipconfig_indicate_state(service,
- CONNMAN_SERVICE_STATE_IDLE,
- CONNMAN_IPCONFIG_TYPE_IPV4);
+ connman_network_set_associating(network, false);
+ network->connecting = false;
+
+ ipconfig_ipv4 = __connman_service_get_ip4config(service);
+
+ DBG("lease lost for ipconfig %p", ipconfig_ipv4);
+
+ if (!ipconfig_ipv4)
+ return;
+
+ __connman_ipconfig_address_remove(ipconfig_ipv4);
+ __connman_ipconfig_gateway_remove(ipconfig_ipv4);
}
static void dhcp_callback(struct connman_network *network,
- connman_bool_t success)
+ bool success, gpointer data)
{
- DBG("success %d", success);
-
- if (success == TRUE)
+ if (success)
dhcp_success(network);
else
dhcp_failure(network);
@@ -210,9 +225,9 @@ static int set_connected_fixed(struct connman_network *network)
set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
- network->connecting = FALSE;
+ network->connecting = false;
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
err = __connman_ipconfig_address_add(ipconfig_ipv4);
if (err < 0)
@@ -243,7 +258,7 @@ static void set_connected_manual(struct connman_network *network)
ipconfig = __connman_service_get_ip4config(service);
- if (__connman_ipconfig_get_local(ipconfig) == NULL)
+ if (!__connman_ipconfig_get_local(ipconfig))
__connman_service_read_ip4config(service);
set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
@@ -256,9 +271,9 @@ static void set_connected_manual(struct connman_network *network)
if (err < 0)
goto err;
- network->connecting = FALSE;
+ network->connecting = false;
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
return;
@@ -294,10 +309,10 @@ static int manual_ipv6_set(struct connman_network *network,
DBG("network %p ipv6 %p", network, ipconfig_ipv6);
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return -EINVAL;
- if (__connman_ipconfig_get_local(ipconfig_ipv6) == NULL)
+ if (!__connman_ipconfig_get_local(ipconfig_ipv6))
__connman_service_read_ip6config(service);
__connman_ipconfig_enable_ipv6(ipconfig_ipv6);
@@ -318,9 +333,9 @@ static int manual_ipv6_set(struct connman_network *network,
__connman_device_set_network(network->device, network);
- connman_device_set_disconnected(network->device, FALSE);
+ connman_device_set_disconnected(network->device, false);
- network->connecting = FALSE;
+ network->connecting = false;
return 0;
}
@@ -331,9 +346,10 @@ static void stop_dhcpv6(struct connman_network *network)
}
static void dhcpv6_release_callback(struct connman_network *network,
- connman_bool_t success)
+ enum __connman_dhcpv6_status status,
+ gpointer data)
{
- DBG("success %d", success);
+ DBG("status %d", status);
stop_dhcpv6(network);
}
@@ -345,26 +361,27 @@ static void release_dhcpv6(struct connman_network *network)
}
static void dhcpv6_info_callback(struct connman_network *network,
- connman_bool_t success)
+ enum __connman_dhcpv6_status status,
+ gpointer data)
{
- DBG("success %d", success);
+ DBG("status %d", status);
stop_dhcpv6(network);
}
-static gboolean dhcpv6_set_addresses(struct connman_network *network)
+static int dhcpv6_set_addresses(struct connman_network *network)
{
struct connman_service *service;
struct connman_ipconfig *ipconfig_ipv6;
int err = -EINVAL;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
goto err;
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
- network->connecting = FALSE;
+ network->connecting = false;
ipconfig_ipv6 = __connman_service_get_ip6config(service);
err = __connman_ipconfig_address_add(ipconfig_ipv6);
@@ -385,7 +402,7 @@ err:
static void autoconf_ipv6_set(struct connman_network *network);
static void dhcpv6_callback(struct connman_network *network,
- connman_bool_t success);
+ enum __connman_dhcpv6_status status, gpointer data);
/*
* Have a separate callback for renew so that we do not do autoconf
@@ -393,25 +410,30 @@ static void dhcpv6_callback(struct connman_network *network,
* DHCPv6 solicitation.
*/
static void dhcpv6_renew_callback(struct connman_network *network,
- connman_bool_t success)
+ enum __connman_dhcpv6_status status,
+ gpointer data)
{
- if (success == TRUE)
- dhcpv6_callback(network, success);
- else {
+ switch (status) {
+ case CONNMAN_DHCPV6_STATUS_SUCCEED:
+ dhcpv6_callback(network, status, data);
+ break;
+ case CONNMAN_DHCPV6_STATUS_FAIL:
+ case CONNMAN_DHCPV6_STATUS_RESTART:
stop_dhcpv6(network);
/* restart and do solicit again. */
autoconf_ipv6_set(network);
+ break;
}
}
static void dhcpv6_callback(struct connman_network *network,
- connman_bool_t success)
+ enum __connman_dhcpv6_status status, gpointer data)
{
- DBG("success %d", success);
+ DBG("status %d", status);
/* Start the renew process if necessary */
- if (success == TRUE) {
+ if (status == CONNMAN_DHCPV6_STATUS_SUCCEED) {
if (dhcpv6_set_addresses(network) < 0) {
stop_dhcpv6(network);
@@ -420,7 +442,13 @@ static void dhcpv6_callback(struct connman_network *network,
if (__connman_dhcpv6_start_renew(network,
dhcpv6_renew_callback) == -ETIMEDOUT)
- dhcpv6_renew_callback(network, FALSE);
+ dhcpv6_renew_callback(network,
+ CONNMAN_DHCPV6_STATUS_FAIL,
+ data);
+
+ } else if (status == CONNMAN_DHCPV6_STATUS_RESTART) {
+ stop_dhcpv6(network);
+ autoconf_ipv6_set(network);
} else
stop_dhcpv6(network);
}
@@ -433,7 +461,7 @@ static void check_dhcpv6(struct nd_router_advert *reply,
DBG("reply %p", reply);
- if (reply == NULL) {
+ if (!reply) {
/*
* Router solicitation message seem to get lost easily so
* try to send it again.
@@ -456,7 +484,7 @@ static void check_dhcpv6(struct nd_router_advert *reply,
* If we were disconnected while waiting router advertisement,
* we just quit and do not start DHCPv6
*/
- if (network->connected == FALSE) {
+ if (!network->connected) {
connman_network_unref(network);
return;
}
@@ -481,7 +509,7 @@ static void receive_refresh_rs_reply(struct nd_router_advert *reply,
DBG("reply %p", reply);
- if (reply == NULL) {
+ if (!reply) {
/*
* Router solicitation message seem to get lost easily so
* try to send it again.
@@ -505,7 +533,8 @@ static void receive_refresh_rs_reply(struct nd_router_advert *reply,
return;
}
-int __connman_refresh_rs_ipv6(struct connman_network *network, int index)
+int __connman_network_refresh_rs_ipv6(struct connman_network *network,
+ int index)
{
int ret = 0;
@@ -546,16 +575,16 @@ static void autoconf_ipv6_set(struct connman_network *network)
__connman_device_set_network(network->device, network);
- connman_device_set_disconnected(network->device, FALSE);
+ connman_device_set_disconnected(network->device, false);
- network->connecting = FALSE;
+ network->connecting = false;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return;
ipconfig = __connman_service_get_ip6config(service);
- if (ipconfig == NULL)
+ if (!ipconfig)
return;
index = __connman_ipconfig_get_index(ipconfig);
@@ -574,10 +603,10 @@ static void set_connected(struct connman_network *network)
struct connman_service *service;
int ret;
- if (network->connected == TRUE)
+ if (network->connected)
return;
- network->connected = TRUE;
+ network->connected = true;
service = connman_service_lookup_from_network(network);
@@ -634,9 +663,9 @@ static void set_connected(struct connman_network *network)
}
}
- network->connecting = FALSE;
+ network->connecting = false;
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
}
static void set_disconnected(struct connman_network *network)
@@ -646,11 +675,6 @@ static void set_disconnected(struct connman_network *network)
enum connman_service_state state;
struct connman_service *service;
- if (network->connected == FALSE)
- return;
-
- network->connected = FALSE;
-
service = connman_service_lookup_from_network(network);
ipconfig_ipv4 = __connman_service_get_ip4config(service);
@@ -672,28 +696,30 @@ static void set_disconnected(struct connman_network *network)
__connman_device_set_network(network->device, NULL);
- switch (ipv6_method) {
- case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
- case CONNMAN_IPCONFIG_METHOD_OFF:
- case CONNMAN_IPCONFIG_METHOD_FIXED:
- case CONNMAN_IPCONFIG_METHOD_MANUAL:
- break;
- case CONNMAN_IPCONFIG_METHOD_DHCP:
- case CONNMAN_IPCONFIG_METHOD_AUTO:
- release_dhcpv6(network);
- break;
- }
+ if (network->connected) {
+ switch (ipv6_method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ break;
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ release_dhcpv6(network);
+ break;
+ }
- switch (ipv4_method) {
- case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
- case CONNMAN_IPCONFIG_METHOD_OFF:
- case CONNMAN_IPCONFIG_METHOD_AUTO:
- case CONNMAN_IPCONFIG_METHOD_FIXED:
- case CONNMAN_IPCONFIG_METHOD_MANUAL:
- break;
- case CONNMAN_IPCONFIG_METHOD_DHCP:
- __connman_dhcp_stop(network);
- break;
+ switch (ipv4_method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ break;
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ __connman_dhcp_stop(network);
+ break;
+ }
}
/*
@@ -717,21 +743,23 @@ static void set_disconnected(struct connman_network *network)
CONNMAN_SERVICE_STATE_DISCONNECT,
CONNMAN_IPCONFIG_TYPE_IPV6);
- __connman_connection_gateway_remove(service,
- CONNMAN_IPCONFIG_TYPE_ALL);
+ if (network->connected) {
+ __connman_connection_gateway_remove(service,
+ CONNMAN_IPCONFIG_TYPE_ALL);
- __connman_ipconfig_address_unset(ipconfig_ipv4);
- __connman_ipconfig_address_unset(ipconfig_ipv6);
+ __connman_ipconfig_address_unset(ipconfig_ipv4);
+ __connman_ipconfig_address_unset(ipconfig_ipv6);
- /*
- * Special handling for IPv6 autoconfigured address.
- * The simplest way to remove autoconfigured routes is to
- * disable IPv6 temporarily so that kernel will do the cleanup
- * automagically.
- */
- if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
- __connman_ipconfig_disable_ipv6(ipconfig_ipv6);
- __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
+ /*
+ * Special handling for IPv6 autoconfigured address.
+ * The simplest way to remove autoconfigured routes is to
+ * disable IPv6 temporarily so that kernel will do the cleanup
+ * automagically.
+ */
+ if (ipv6_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
+ __connman_ipconfig_disable_ipv6(ipconfig_ipv6);
+ __connman_ipconfig_enable_ipv6(ipconfig_ipv6);
+ }
}
__connman_service_ipconfig_indicate_state(service,
@@ -742,9 +770,10 @@ static void set_disconnected(struct connman_network *network)
CONNMAN_SERVICE_STATE_IDLE,
CONNMAN_IPCONFIG_TYPE_IPV6);
- network->connecting = FALSE;
+ network->connecting = false;
+ network->connected = false;
- connman_network_set_associating(network, FALSE);
+ connman_network_set_associating(network, false);
}
@@ -756,13 +785,13 @@ static int network_probe(struct connman_network *network)
DBG("network %p name %s", network, network->name);
- if (network->driver != NULL)
+ if (network->driver)
return -EALREADY;
for (list = driver_list; list; list = list->next) {
driver = list->data;
- if (match_driver(network, driver) == FALSE) {
+ if (!match_driver(network, driver)) {
driver = NULL;
continue;
}
@@ -775,10 +804,10 @@ static int network_probe(struct connman_network *network)
driver = NULL;
}
- if (driver == NULL)
+ if (!driver)
return -ENODEV;
- if (network->group == NULL)
+ if (!network->group)
return -EINVAL;
switch (network->type) {
@@ -786,12 +815,13 @@ static int network_probe(struct connman_network *network)
case CONNMAN_NETWORK_TYPE_VENDOR:
return 0;
case CONNMAN_NETWORK_TYPE_ETHERNET:
+ case CONNMAN_NETWORK_TYPE_GADGET:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
case CONNMAN_NETWORK_TYPE_WIFI:
network->driver = driver;
- if (__connman_service_create_from_network(network) == NULL) {
+ if (!__connman_service_create_from_network(network)) {
network->driver = NULL;
return -EINVAL;
}
@@ -804,10 +834,10 @@ static void network_remove(struct connman_network *network)
{
DBG("network %p name %s", network, network->name);
- if (network->driver == NULL)
+ if (!network->driver)
return;
- if (network->connected == TRUE)
+ if (network->connected)
set_disconnected(network);
switch (network->type) {
@@ -815,11 +845,12 @@ static void network_remove(struct connman_network *network)
case CONNMAN_NETWORK_TYPE_VENDOR:
break;
case CONNMAN_NETWORK_TYPE_ETHERNET:
+ case CONNMAN_NETWORK_TYPE_GADGET:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
case CONNMAN_NETWORK_TYPE_WIFI:
- if (network->group != NULL) {
+ if (network->group) {
__connman_service_remove_from_network(network);
g_free(network->group);
@@ -838,17 +869,17 @@ static void network_change(struct connman_network *network)
{
DBG("network %p name %s", network, network->name);
- if (network->connected == FALSE)
+ if (!network->connected)
return;
- connman_device_set_disconnected(network->device, TRUE);
+ connman_device_set_disconnected(network->device, true);
if (network->driver && network->driver->disconnect) {
network->driver->disconnect(network);
return;
}
- network->connected = FALSE;
+ network->connected = false;
}
static void probe_driver(struct connman_network_driver *driver)
@@ -857,10 +888,10 @@ static void probe_driver(struct connman_network_driver *driver)
DBG("driver %p name %s", driver, driver->name);
- for (list = network_list; list != NULL; list = list->next) {
+ for (list = network_list; list; list = list->next) {
struct connman_network *network = list->data;
- if (network->driver != NULL)
+ if (network->driver)
continue;
if (driver->type != network->type)
@@ -879,7 +910,7 @@ static void remove_driver(struct connman_network_driver *driver)
DBG("driver %p name %s", driver, driver->name);
- for (list = network_list; list != NULL; list = list->next) {
+ for (list = network_list; list; list = list->next) {
struct connman_network *network = list->data;
if (network->driver == driver)
@@ -938,7 +969,6 @@ static void network_destruct(struct connman_network *network)
g_free(network->wifi.mode);
g_free(network->wifi.security);
g_free(network->wifi.passphrase);
- g_free(network->wifi.agent_passphrase);
g_free(network->wifi.eap);
g_free(network->wifi.identity);
g_free(network->wifi.agent_identity);
@@ -977,7 +1007,7 @@ struct connman_network *connman_network_create(const char *identifier,
DBG("identifier %s type %d", identifier, type);
network = g_try_new0(struct connman_network, 1);
- if (network == NULL)
+ if (!network)
return NULL;
DBG("network %p", network);
@@ -986,7 +1016,7 @@ struct connman_network *connman_network_create(const char *identifier,
ident = g_strdup(identifier);
- if (ident == NULL) {
+ if (!ident) {
g_free(network);
return NULL;
}
@@ -1048,7 +1078,8 @@ const char *__connman_network_get_type(struct connman_network *network)
*
* Get type of network
*/
-enum connman_network_type connman_network_get_type(struct connman_network *network)
+enum connman_network_type connman_network_get_type(
+ struct connman_network *network)
{
return network->type;
}
@@ -1077,11 +1108,11 @@ void connman_network_set_index(struct connman_network *network, int index)
struct connman_ipconfig *ipconfig;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
goto done;
ipconfig = __connman_service_get_ip4config(service);
- if (ipconfig == NULL)
+ if (!ipconfig)
goto done;
/* If index changed, the index of ipconfig must be reset. */
@@ -1119,6 +1150,7 @@ void connman_network_set_group(struct connman_network *network,
case CONNMAN_NETWORK_TYPE_VENDOR:
return;
case CONNMAN_NETWORK_TYPE_ETHERNET:
+ case CONNMAN_NETWORK_TYPE_GADGET:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
@@ -1127,12 +1159,12 @@ void connman_network_set_group(struct connman_network *network,
}
if (g_strcmp0(network->group, group) == 0) {
- if (group != NULL)
+ if (group)
__connman_service_update_from_network(network);
return;
}
- if (network->group != NULL) {
+ if (network->group) {
__connman_service_remove_from_network(network);
g_free(network->group);
@@ -1140,7 +1172,7 @@ void connman_network_set_group(struct connman_network *network,
network->group = g_strdup(group);
- if (network->group != NULL)
+ if (network->group)
network_probe(network);
}
@@ -1157,34 +1189,33 @@ const char *connman_network_get_group(struct connman_network *network)
const char *__connman_network_get_ident(struct connman_network *network)
{
- if (network->device == NULL)
+ if (!network->device)
return NULL;
return connman_device_get_ident(network->device);
}
-connman_bool_t __connman_network_get_weakness(struct connman_network *network)
+bool __connman_network_get_weakness(struct connman_network *network)
{
switch (network->type) {
case CONNMAN_NETWORK_TYPE_UNKNOWN:
case CONNMAN_NETWORK_TYPE_VENDOR:
case CONNMAN_NETWORK_TYPE_ETHERNET:
+ case CONNMAN_NETWORK_TYPE_GADGET:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
break;
case CONNMAN_NETWORK_TYPE_WIFI:
- if (g_strcmp0(network->wifi.mode, "adhoc") == 0)
- return TRUE;
if (network->strength > 0 && network->strength < 20)
- return TRUE;
+ return true;
break;
}
- return FALSE;
+ return false;
}
-connman_bool_t connman_network_get_connecting(struct connman_network *network)
+bool connman_network_get_connecting(struct connman_network *network)
{
return network->connecting;
}
@@ -1197,7 +1228,7 @@ connman_bool_t connman_network_get_connecting(struct connman_network *network)
* Change availability state of network (in range)
*/
int connman_network_set_available(struct connman_network *network,
- connman_bool_t available)
+ bool available)
{
DBG("network %p available %d", network, available);
@@ -1215,7 +1246,7 @@ int connman_network_set_available(struct connman_network *network,
*
* Get network available setting
*/
-connman_bool_t connman_network_get_available(struct connman_network *network)
+bool connman_network_get_available(struct connman_network *network)
{
return network->available;
}
@@ -1228,7 +1259,7 @@ connman_bool_t connman_network_get_available(struct connman_network *network)
* Change associating state of network
*/
int connman_network_set_associating(struct connman_network *network,
- connman_bool_t associating)
+ bool associating)
{
DBG("network %p associating %d", network, associating);
@@ -1237,7 +1268,7 @@ int connman_network_set_associating(struct connman_network *network,
network->associating = associating;
- if (associating == TRUE) {
+ if (associating) {
struct connman_service *service;
service = connman_service_lookup_from_network(network);
@@ -1299,11 +1330,11 @@ void connman_network_set_ipv4_method(struct connman_network *network,
struct connman_ipconfig *ipconfig;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return;
ipconfig = __connman_service_get_ip4config(service);
- if (ipconfig == NULL)
+ if (!ipconfig)
return;
__connman_ipconfig_set_method(ipconfig, method);
@@ -1316,11 +1347,11 @@ void connman_network_set_ipv6_method(struct connman_network *network,
struct connman_ipconfig *ipconfig;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return;
ipconfig = __connman_service_get_ip6config(service);
- if (ipconfig == NULL)
+ if (!ipconfig)
return;
__connman_ipconfig_set_method(ipconfig, method);
@@ -1331,8 +1362,8 @@ void connman_network_set_error(struct connman_network *network,
{
DBG("network %p error %d", network, error);
- network->connecting = FALSE;
- network->associating = FALSE;
+ network->connecting = false;
+ network->associating = false;
switch (error) {
case CONNMAN_NETWORK_ERROR_UNKNOWN:
@@ -1360,10 +1391,10 @@ void connman_network_clear_error(struct connman_network *network)
DBG("network %p", network);
- if (network == NULL)
+ if (!network)
return;
- if (network->connecting == TRUE || network->associating == TRUE)
+ if (network->connecting || network->associating)
return;
service = connman_service_lookup_from_network(network);
@@ -1378,14 +1409,14 @@ void connman_network_clear_error(struct connman_network *network)
* Change connected state of network
*/
int connman_network_set_connected(struct connman_network *network,
- connman_bool_t connected)
+ bool connected)
{
DBG("network %p connected %d/%d connecting %d associating %d",
network, network->connected, connected, network->connecting,
network->associating);
- if ((network->connecting == TRUE || network->associating == TRUE) &&
- connected == FALSE) {
+ if ((network->connecting || network->associating) &&
+ !connected) {
connman_network_set_error(network,
CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
if (__connman_network_disconnect(network) == 0)
@@ -1395,7 +1426,7 @@ int connman_network_set_connected(struct connman_network *network,
if (network->connected == connected)
return -EALREADY;
- if (connected == FALSE)
+ if (!connected)
set_disconnected(network);
else
set_connected(network);
@@ -1409,7 +1440,7 @@ int connman_network_set_connected(struct connman_network *network,
*
* Get network connection status
*/
-connman_bool_t connman_network_get_connected(struct connman_network *network)
+bool connman_network_get_connected(struct connman_network *network)
{
return network->connected;
}
@@ -1420,14 +1451,14 @@ connman_bool_t connman_network_get_connected(struct connman_network *network)
*
* Get network associating status
*/
-connman_bool_t connman_network_get_associating(struct connman_network *network)
+bool connman_network_get_associating(struct connman_network *network)
{
return network->associating;
}
void connman_network_clear_hidden(void *user_data)
{
- if (user_data == NULL)
+ if (!user_data)
return;
DBG("user_data %p", user_data);
@@ -1442,7 +1473,7 @@ void connman_network_clear_hidden(void *user_data)
}
int connman_network_connect_hidden(struct connman_network *network,
- char *identity, char* passphrase, void *user_data)
+ char *identity, char *passphrase, void *user_data)
{
int err = 0;
struct connman_service *service;
@@ -1451,15 +1482,13 @@ int connman_network_connect_hidden(struct connman_network *network,
DBG("network %p service %p user_data %p", network, service, user_data);
- if (service == NULL) {
- err = -EINVAL;
- goto out;
- }
+ if (!service)
+ return -EINVAL;
- if (identity != NULL)
+ if (identity)
__connman_service_set_agent_identity(service, identity);
- if (passphrase != NULL)
+ if (passphrase)
err = __connman_service_add_passphrase(service, passphrase);
if (err == -ENOKEY) {
@@ -1468,9 +1497,9 @@ int connman_network_connect_hidden(struct connman_network *network,
goto out;
} else {
__connman_service_set_hidden(service);
- __connman_service_set_userconnect(service, TRUE);
__connman_service_set_hidden_data(service, user_data);
- return __connman_service_connect(service);
+ return __connman_service_connect(service,
+ CONNMAN_SERVICE_CONNECT_REASON_USER);
}
out:
@@ -1490,32 +1519,31 @@ int __connman_network_connect(struct connman_network *network)
DBG("network %p", network);
- if (network->connected == TRUE)
+ if (network->connected)
return -EISCONN;
- if (network->connecting == TRUE || network->associating == TRUE)
+ if (network->connecting || network->associating)
return -EALREADY;
- if (network->driver == NULL)
+ if (!network->driver)
return -EUNATCH;
- if (network->driver->connect == NULL)
+ if (!network->driver->connect)
return -ENOSYS;
- if (network->device == NULL)
+ if (!network->device)
return -ENODEV;
- network->connecting = TRUE;
+ network->connecting = true;
__connman_device_disconnect(network->device);
err = network->driver->connect(network);
if (err < 0) {
if (err == -EINPROGRESS)
- connman_network_set_associating(network, TRUE);
- else {
- network->connecting = FALSE;
- }
+ connman_network_set_associating(network, true);
+ else
+ network->connecting = false;
return err;
}
@@ -1533,24 +1561,23 @@ int __connman_network_connect(struct connman_network *network)
*/
int __connman_network_disconnect(struct connman_network *network)
{
- int err;
+ int err = 0;
DBG("network %p", network);
- if (network->connected == FALSE && network->connecting == FALSE &&
- network->associating == FALSE)
+ if (!network->connected && !network->connecting &&
+ !network->associating)
return -ENOTCONN;
- if (network->driver == NULL)
+ if (!network->driver)
return -EUNATCH;
- if (network->driver->disconnect == NULL)
- return -ENOSYS;
+ network->connecting = false;
- network->connecting = FALSE;
+ if (network->driver->disconnect)
+ err = network->driver->disconnect(network);
- err = network->driver->disconnect(network);
- if (err == 0)
+ if (err != -EINPROGRESS)
set_disconnected(network);
return err;
@@ -1563,7 +1590,7 @@ static int manual_ipv4_set(struct connman_network *network,
int err;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return -EINVAL;
err = __connman_ipconfig_address_add(ipconfig);
@@ -1584,7 +1611,7 @@ int __connman_network_clear_ipconfig(struct connman_network *network,
enum connman_ipconfig_type type;
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return -EINVAL;
method = __connman_ipconfig_get_method(ipconfig);
@@ -1625,7 +1652,7 @@ int __connman_network_set_ipconfig(struct connman_network *network,
enum connman_ipconfig_method method;
int ret;
- if (network == NULL)
+ if (!network)
return -EINVAL;
if (ipconfig_ipv6) {
@@ -1680,11 +1707,11 @@ int connman_network_set_ipaddress(struct connman_network *network,
DBG("network %p", network);
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return -EINVAL;
ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
- if (ipconfig == NULL)
+ if (!ipconfig)
return -EINVAL;
__connman_ipconfig_set_local(ipconfig, ipaddress->local);
@@ -1706,19 +1733,19 @@ int connman_network_set_nameservers(struct connman_network *network,
DBG("network %p nameservers %s", network, nameservers);
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return -EINVAL;
__connman_service_nameserver_clear(service);
- if (nameservers == NULL)
+ if (!nameservers)
return 0;
nameservers_array = g_strsplit(nameservers, " ", 0);
- for (i = 0; nameservers_array[i] != NULL; i++) {
+ for (i = 0; nameservers_array[i]; i++) {
__connman_service_nameserver_append(service,
- nameservers_array[i], FALSE);
+ nameservers_array[i], false);
}
g_strfreev(nameservers_array);
@@ -1734,7 +1761,7 @@ int connman_network_set_domain(struct connman_network *network,
DBG("network %p domain %s", network, domain);
service = connman_service_lookup_from_network(network);
- if (service == NULL)
+ if (!service)
return -EINVAL;
__connman_service_set_domainname(service, domain);
@@ -1829,49 +1856,46 @@ int connman_network_set_string(struct connman_network *network,
if (g_strcmp0(key, "Name") == 0)
return connman_network_set_name(network, value);
- if (g_str_equal(key, "Path") == TRUE) {
+ if (g_str_equal(key, "Path")) {
g_free(network->path);
network->path = g_strdup(value);
- } else if (g_str_equal(key, "Node") == TRUE) {
+ } else if (g_str_equal(key, "Node")) {
g_free(network->node);
network->node = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.Mode") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.Mode")) {
g_free(network->wifi.mode);
network->wifi.mode = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.Security") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.Security")) {
g_free(network->wifi.security);
network->wifi.security = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.Passphrase") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.Passphrase")) {
g_free(network->wifi.passphrase);
network->wifi.passphrase = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE) {
- g_free(network->wifi.agent_passphrase);
- network->wifi.agent_passphrase = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.EAP")) {
g_free(network->wifi.eap);
network->wifi.eap = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.Identity")) {
g_free(network->wifi.identity);
network->wifi.identity = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.AgentIdentity")) {
g_free(network->wifi.agent_identity);
network->wifi.agent_identity = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.CACertFile")) {
g_free(network->wifi.ca_cert_path);
network->wifi.ca_cert_path = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.ClientCertFile")) {
g_free(network->wifi.client_cert_path);
network->wifi.client_cert_path = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.PrivateKeyFile")) {
g_free(network->wifi.private_key_path);
network->wifi.private_key_path = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase")) {
g_free(network->wifi.private_key_passphrase);
network->wifi.private_key_passphrase = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.Phase2")) {
g_free(network->wifi.phase2_auth);
network->wifi.phase2_auth = g_strdup(value);
- } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
+ } else if (g_str_equal(key, "WiFi.PinWPS")) {
g_free(network->wifi.pin_wps);
network->wifi.pin_wps = g_strdup(value);
} else {
@@ -1893,37 +1917,35 @@ const char *connman_network_get_string(struct connman_network *network,
{
DBG("network %p key %s", network, key);
- if (g_str_equal(key, "Path") == TRUE)
+ if (g_str_equal(key, "Path"))
return network->path;
- else if (g_str_equal(key, "Name") == TRUE)
+ else if (g_str_equal(key, "Name"))
return network->name;
- else if (g_str_equal(key, "Node") == TRUE)
+ else if (g_str_equal(key, "Node"))
return network->node;
- else if (g_str_equal(key, "WiFi.Mode") == TRUE)
+ else if (g_str_equal(key, "WiFi.Mode"))
return network->wifi.mode;
- else if (g_str_equal(key, "WiFi.Security") == TRUE)
+ else if (g_str_equal(key, "WiFi.Security"))
return network->wifi.security;
- else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
+ else if (g_str_equal(key, "WiFi.Passphrase"))
return network->wifi.passphrase;
- else if (g_str_equal(key, "WiFi.AgentPassphrase") == TRUE)
- return network->wifi.agent_passphrase;
- else if (g_str_equal(key, "WiFi.EAP") == TRUE)
+ else if (g_str_equal(key, "WiFi.EAP"))
return network->wifi.eap;
- else if (g_str_equal(key, "WiFi.Identity") == TRUE)
+ else if (g_str_equal(key, "WiFi.Identity"))
return network->wifi.identity;
- else if (g_str_equal(key, "WiFi.AgentIdentity") == TRUE)
+ else if (g_str_equal(key, "WiFi.AgentIdentity"))
return network->wifi.agent_identity;
- else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
+ else if (g_str_equal(key, "WiFi.CACertFile"))
return network->wifi.ca_cert_path;
- else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
+ else if (g_str_equal(key, "WiFi.ClientCertFile"))
return network->wifi.client_cert_path;
- else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
+ else if (g_str_equal(key, "WiFi.PrivateKeyFile"))
return network->wifi.private_key_path;
- else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
+ else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase"))
return network->wifi.private_key_passphrase;
- else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
+ else if (g_str_equal(key, "WiFi.Phase2"))
return network->wifi.phase2_auth;
- else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
+ else if (g_str_equal(key, "WiFi.PinWPS"))
return network->wifi.pin_wps;
return NULL;
@@ -1938,7 +1960,7 @@ const char *connman_network_get_string(struct connman_network *network,
* Set boolean value for specific key
*/
int connman_network_set_bool(struct connman_network *network,
- const char *key, connman_bool_t value)
+ const char *key, bool value)
{
DBG("network %p key %s value %d", network, key, value);
@@ -1959,19 +1981,19 @@ int connman_network_set_bool(struct connman_network *network,
*
* Get boolean value for specific key
*/
-connman_bool_t connman_network_get_bool(struct connman_network *network,
+bool connman_network_get_bool(struct connman_network *network,
const char *key)
{
DBG("network %p key %s", network, key);
- if (g_str_equal(key, "Roaming") == TRUE)
+ if (g_str_equal(key, "Roaming"))
return network->roaming;
- else if (g_str_equal(key, "WiFi.WPS") == TRUE)
+ else if (g_str_equal(key, "WiFi.WPS"))
return network->wifi.wps;
- else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
+ else if (g_str_equal(key, "WiFi.UseWPS"))
return network->wifi.use_wps;
- return FALSE;
+ return false;
}
/**
@@ -1988,10 +2010,10 @@ int connman_network_set_blob(struct connman_network *network,
{
DBG("network %p key %s size %d", network, key, size);
- if (g_str_equal(key, "WiFi.SSID") == TRUE) {
+ if (g_str_equal(key, "WiFi.SSID")) {
g_free(network->wifi.ssid);
network->wifi.ssid = g_try_malloc(size);
- if (network->wifi.ssid != NULL) {
+ if (network->wifi.ssid) {
memcpy(network->wifi.ssid, data, size);
network->wifi.ssid_len = size;
} else
@@ -2016,8 +2038,8 @@ const void *connman_network_get_blob(struct connman_network *network,
{
DBG("network %p key %s", network, key);
- if (g_str_equal(key, "WiFi.SSID") == TRUE) {
- if (size != NULL)
+ if (g_str_equal(key, "WiFi.SSID")) {
+ if (size)
*size = network->wifi.ssid_len;
return network->wifi.ssid;
}
@@ -2031,12 +2053,12 @@ void __connman_network_set_device(struct connman_network *network,
if (network->device == device)
return;
- if (network->device != NULL)
+ if (network->device)
network_remove(network);
network->device = device;
- if (network->device != NULL)
+ if (network->device)
network_probe(network);
}
@@ -2081,6 +2103,7 @@ void connman_network_update(struct connman_network *network)
case CONNMAN_NETWORK_TYPE_VENDOR:
return;
case CONNMAN_NETWORK_TYPE_ETHERNET:
+ case CONNMAN_NETWORK_TYPE_GADGET:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
@@ -2088,7 +2111,7 @@ void connman_network_update(struct connman_network *network)
break;
}
- if (network->group != NULL)
+ if (network->group)
__connman_service_update_from_network(network);
}