static GSList *network_list = NULL;
static GSList *driver_list = NULL;
-static unsigned int hidden_counter = 0;
struct connman_network {
- gint refcount;
+ int refcount;
enum connman_network_type type;
connman_bool_t available;
connman_bool_t connected;
connman_bool_t roaming;
- connman_bool_t hidden;
connman_uint8_t strength;
connman_uint16_t frequency;
char *identifier;
char *group;
char *path;
int index;
+ int router_solicit_count;
struct connman_network_driver *driver;
void *driver_data;
if (network->driver == NULL)
return;
+ connman_network_set_connected(network, FALSE);
+
switch (network->type) {
case CONNMAN_NETWORK_TYPE_UNKNOWN:
case CONNMAN_NETWORK_TYPE_VENDOR:
network->refcount = 1;
- if (identifier == NULL) {
- ident = g_strdup_printf("hidden_%d", hidden_counter++);
- network->hidden = TRUE;
- } else
- ident = g_strdup(identifier);
+ ident = g_strdup(identifier);
if (ident == NULL) {
g_free(network);
struct connman_network *connman_network_ref(struct connman_network *network)
{
DBG("network %p name %s refcount %d", network, network->name,
- g_atomic_int_get(&network->refcount) + 1);
+ network->refcount + 1);
- g_atomic_int_inc(&network->refcount);
+ __sync_fetch_and_add(&network->refcount, 1);
return network;
}
void connman_network_unref(struct connman_network *network)
{
DBG("network %p name %s refcount %d", network, network->name,
- g_atomic_int_get(&network->refcount) - 1);
+ network->refcount - 1);
- if (g_atomic_int_dec_and_test(&network->refcount) == FALSE)
+ if (__sync_fetch_and_sub(&network->refcount, 1) != 1)
return;
network_list = g_slist_remove(network_list, network);
*/
connman_bool_t connman_network_get_available(struct connman_network *network)
{
- if (network->hidden == TRUE)
- return TRUE;
-
return network->available;
}
{
struct connman_service *service;
- if (network->associating == FALSE)
- return ;
-
- network->associating = FALSE;
-
service = __connman_service_lookup_from_network(network);
- __connman_service_ipconfig_indicate_state(service,
- CONNMAN_SERVICE_STATE_FAILURE,
- CONNMAN_IPCONFIG_TYPE_IPV4);
+ __connman_service_indicate_error(service,
+ CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
}
static void set_configure_error(struct connman_network *network)
{
struct connman_service *service;
- network->connecting = FALSE;
-
service = __connman_service_lookup_from_network(network);
- __connman_service_ipconfig_indicate_state(service,
- CONNMAN_SERVICE_STATE_FAILURE,
- CONNMAN_IPCONFIG_TYPE_IPV4);
+ __connman_service_indicate_error(service,
+ CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
}
static void set_invalid_key_error(struct connman_network *network)
DBG("nework %p, error %d", network, error);
network->connecting = FALSE;
+ network->associating = FALSE;
switch (error) {
case CONNMAN_NETWORK_ERROR_UNKNOWN:
__connman_service_clear_error(service);
}
-static void set_configuration(struct connman_network *network)
+static void set_configuration(struct connman_network *network,
+ enum connman_ipconfig_type type)
{
struct connman_service *service;
DBG("network %p", network);
- __connman_device_increase_connections(network->device);
+ if (network->device == NULL)
+ return;
__connman_device_set_network(network->device, network);
service = __connman_service_lookup_from_network(network);
__connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_CONFIGURATION,
- CONNMAN_IPCONFIG_TYPE_IPV4);
+ type);
}
static void dhcp_success(struct connman_network *network)
ipconfig_ipv4 = __connman_service_get_ip4config(service);
- set_configuration(network);
+ set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
network->connecting = FALSE;
ipconfig = __connman_service_get_ip4config(service);
- set_configuration(network);
+ if (__connman_ipconfig_get_local(ipconfig) == NULL)
+ __connman_service_read_ip4config(service);
+
+ set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
err = __connman_ipconfig_address_add(ipconfig);
if (err < 0)
DBG("network %p", network);
- set_configuration(network);
+ set_configuration(network, CONNMAN_IPCONFIG_TYPE_IPV4);
err = __connman_dhcp_start(network, dhcp_callback);
if (err < 0) {
if (service == NULL)
return -EINVAL;
+ if (__connman_ipconfig_get_local(ipconfig_ipv6) == NULL)
+ __connman_service_read_ip6config(service);
+
err = __connman_ipconfig_address_add(ipconfig_ipv6);
if (err < 0) {
connman_network_set_error(network,
__connman_connection_gateway_activate(service,
CONNMAN_IPCONFIG_TYPE_IPV6);
- __connman_device_increase_connections(network->device);
-
__connman_device_set_network(network->device, network);
connman_device_set_disconnected(network->device, FALSE);
return 0;
}
+static void stop_dhcpv6(struct connman_network *network)
+{
+ __connman_dhcpv6_stop(network);
+}
+
+static void dhcpv6_info_callback(struct connman_network *network,
+ connman_bool_t success)
+{
+ DBG("success %d", success);
+
+ stop_dhcpv6(network);
+}
+
+static void check_dhcpv6(struct nd_router_advert *reply, void *user_data)
+{
+ struct connman_network *network = user_data;
+
+ DBG("reply %p", reply);
+
+ if (reply == NULL) {
+ /*
+ * Router solicitation message seem to get lost easily so
+ * try to send it again.
+ */
+ if (network->router_solicit_count > 0) {
+ DBG("re-send router solicitation %d",
+ network->router_solicit_count);
+ network->router_solicit_count--;
+ __connman_inet_ipv6_send_rs(network->index, 1,
+ check_dhcpv6, network);
+ return;
+ }
+ connman_network_unref(network);
+ return;
+ }
+
+ network->router_solicit_count = 0;
+
+ /* We do stateless DHCPv6 only if router advertisement says so */
+ if (reply->nd_ra_flags_reserved & ND_RA_FLAG_OTHER)
+ __connman_dhcpv6_start_info(network, dhcpv6_info_callback);
+
+ connman_network_unref(network);
+}
+
static void autoconf_ipv6_set(struct connman_network *network)
{
- DBG("network %p", network);
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig;
+ int index;
- __connman_device_increase_connections(network->device);
+ DBG("network %p", network);
__connman_device_set_network(network->device, network);
connman_device_set_disconnected(network->device, FALSE);
- /* XXX: Append IPv6 nameservers here */
-
network->connecting = FALSE;
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return;
+
+ ipconfig = __connman_service_get_ip6config(service);
+ if (ipconfig == NULL)
+ return;
+
+ index = connman_ipconfig_get_index(ipconfig);
+
+ connman_network_ref(network);
+
+ /* Try to get stateless DHCPv6 information, RFC 3736 */
+ network->router_solicit_count = 3;
+ __connman_inet_ipv6_send_rs(index, 1, check_dhcpv6, network);
}
static gboolean set_connected(gpointer user_data)
}
} else {
- struct connman_service *service;
+ enum connman_service_state state;
+
+ /*
+ * Resetting solicit count here will prevent the RS resend loop
+ * from sending packets in check_dhcpv6()
+ */
+ network->router_solicit_count = 0;
__connman_device_set_network(network->device, NULL);
- network->hidden = FALSE;
- service = __connman_service_lookup_from_network(network);
+ switch (ipv6_method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ break;
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ stop_dhcpv6(network);
+ break;
+ }
switch (ipv4_method) {
case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
break;
}
- __connman_service_ipconfig_indicate_state(service,
+ /*
+ * We only set the disconnect state if we were not in idle
+ * or in failure. It does not make sense to go to disconnect
+ * state if we were not connected.
+ */
+ state = __connman_service_ipconfig_get_state(service,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+ if (state != CONNMAN_SERVICE_STATE_IDLE &&
+ state != CONNMAN_SERVICE_STATE_FAILURE)
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_DISCONNECT,
CONNMAN_IPCONFIG_TYPE_IPV4);
- __connman_service_ipconfig_indicate_state(service,
+ state = __connman_service_ipconfig_get_state(service,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
+ if (state != CONNMAN_SERVICE_STATE_IDLE &&
+ state != CONNMAN_SERVICE_STATE_FAILURE)
+ __connman_service_ipconfig_indicate_state(service,
CONNMAN_SERVICE_STATE_DISCONNECT,
CONNMAN_IPCONFIG_TYPE_IPV6);
if (network->connected == connected)
return -EALREADY;
- if (connected == FALSE)
- __connman_device_decrease_connections(network->device);
-
network->connected = connected;
set_connected(network);
return network->associating;
}
+int connman_network_connect_hidden(struct connman_network *network,
+ char *identity, char* passphrase)
+{
+ struct connman_service *service;
+
+ DBG("");
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return -EINVAL;
+
+ if (identity != NULL)
+ __connman_service_set_agent_identity(service, identity);
+
+ if (passphrase != NULL)
+ __connman_service_add_passphrase(service, passphrase);
+
+ return __connman_service_connect(service);
+}
+
/**
* __connman_network_connect:
* @network: network structure
connman_network_set_associating(network, TRUE);
else {
network->connecting = FALSE;
- network->hidden = FALSE;
}
return err;
enum connman_ipconfig_method method;
int ret;
+ if (network == NULL)
+ return -EINVAL;
+
if (ipconfig_ipv6) {
method = __connman_ipconfig_get_method(ipconfig_ipv6);
const char *nameservers)
{
struct connman_service *service;
- char **nameservers_array = NULL;
+ char **nameservers_array;
int i;
DBG("network %p nameservers %s", network, nameservers);
__connman_service_nameserver_clear(service);
- if (nameservers != NULL)
- nameservers_array = g_strsplit(nameservers, " ", 0);
+ if (nameservers == NULL)
+ return 0;
+
+ nameservers_array = g_strsplit(nameservers, " ", 0);
for (i = 0; nameservers_array[i] != NULL; i++) {
__connman_service_nameserver_append(service,
- nameservers_array[i]);
+ nameservers_array[i], FALSE);
}
g_strfreev(nameservers_array);
}
/**
- * connman_network_set_roaming:
- * @network: network structure
- * @roaming: roaming state
- *
- * Set roaming state for network
- */
-int connman_network_set_roaming(struct connman_network *network,
- connman_bool_t roaming)
-{
- DBG("network %p roaming %d", network, roaming);
-
- network->roaming = roaming;
-
- return 0;
-}
-
-/**
* connman_network_set_string:
* @network: network structure
* @key: unique identifier
DBG("network %p key %s value %d", network, key, value);
if (g_strcmp0(key, "Roaming") == 0)
- return connman_network_set_roaming(network, value);
+ network->roaming = value;
else if (g_strcmp0(key, "WiFi.WPS") == 0)
network->wifi.wps = value;
else if (g_strcmp0(key, "WiFi.UseWPS") == 0)