*
* Connection Manager
*
- * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2010 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
#include <errno.h>
#include <string.h>
-#include <gdbus.h>
-
#include "connman.h"
static unsigned int hidden_counter = 0;
struct connman_network {
struct connman_element element;
enum connman_network_type type;
- enum connman_network_protocol protocol;
connman_bool_t available;
connman_bool_t connected;
connman_bool_t roaming;
connman_uint8_t strength;
connman_uint16_t frequency;
char *identifier;
- char *address;
char *name;
char *node;
char *group;
- struct connman_ipconfig *ipconfig;
struct connman_network_driver *driver;
void *driver_data;
- connman_bool_t registered;
connman_bool_t connecting;
connman_bool_t associating;
unsigned short channel;
char *security;
char *passphrase;
+ char *eap;
+ char *identity;
+ char *ca_cert_path;
+ char *client_cert_path;
+ char *private_key_path;
+ char *private_key_passphrase;
+ char *phase2_auth;
+ connman_bool_t wps;
+ connman_bool_t use_wps;
+ char *pin_wps;
} wifi;
};
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
return "bluetooth";
case CONNMAN_NETWORK_TYPE_CELLULAR:
- case CONNMAN_NETWORK_TYPE_MBM:
- case CONNMAN_NETWORK_TYPE_HSO:
return "cellular";
}
return NULL;
}
-static DBusMessage *get_properties(DBusConnection *conn,
- DBusMessage *msg, void *data)
-{
- struct connman_network *network = data;
- DBusMessage *reply;
- DBusMessageIter array, dict;
-
- DBG("conn %p", conn);
-
- if (__connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_PUBLIC) < 0)
- return __connman_error_permission_denied(msg);
-
- reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
- return NULL;
-
- dbus_message_iter_init_append(reply, &array);
-
- connman_dbus_dict_open(&array, &dict);
-
- if (network->device) {
- const char *path = connman_device_get_path(network->device);
- if (path != NULL)
- connman_dbus_dict_append_variant(&dict, "Device",
- DBUS_TYPE_OBJECT_PATH, &path);
- }
-
- if (network->address != NULL)
- connman_dbus_dict_append_variant(&dict, "Address",
- DBUS_TYPE_STRING, &network->address);
-
- if (network->name != NULL)
- connman_dbus_dict_append_variant(&dict, "Name",
- DBUS_TYPE_STRING, &network->name);
-
- connman_dbus_dict_append_variant(&dict, "Connected",
- DBUS_TYPE_BOOLEAN, &network->connected);
-
- if (network->strength > 0)
- connman_dbus_dict_append_variant(&dict, "Strength",
- DBUS_TYPE_BYTE, &network->strength);
-
- if (network->frequency > 0)
- connman_dbus_dict_append_variant(&dict, "Frequency",
- DBUS_TYPE_UINT16, &network->frequency);
-
- if (network->wifi.ssid != NULL && network->wifi.ssid_len > 0)
- connman_dbus_dict_append_fixed_array(&dict, "WiFi.SSID",
- DBUS_TYPE_BYTE, &network->wifi.ssid,
- network->wifi.ssid_len);
-
- if (network->wifi.mode != NULL)
- connman_dbus_dict_append_variant(&dict, "WiFi.Mode",
- DBUS_TYPE_STRING, &network->wifi.mode);
-
- if (network->wifi.channel > 0)
- connman_dbus_dict_append_variant(&dict, "WiFi.Channel",
- DBUS_TYPE_UINT16, &network->wifi.channel);
-
- if (network->wifi.security != NULL)
- connman_dbus_dict_append_variant(&dict, "WiFi.Security",
- DBUS_TYPE_STRING, &network->wifi.security);
-
- if (network->wifi.passphrase != NULL &&
- __connman_security_check_privilege(msg,
- CONNMAN_SECURITY_PRIVILEGE_SECRET) == 0)
- connman_dbus_dict_append_variant(&dict, "WiFi.Passphrase",
- DBUS_TYPE_STRING, &network->wifi.passphrase);
-
- connman_dbus_dict_close(&array, &dict);
-
- return reply;
-}
-
-static GDBusMethodTable network_methods[] = {
- { "GetProperties", "", "a{sv}", get_properties },
- { },
-};
-
-static GDBusSignalTable network_signals[] = {
- { "PropertyChanged", "sv" },
- { },
-};
-
-static DBusConnection *connection;
-
-static void append_networks(struct connman_device *device,
- DBusMessageIter *entry)
-{
- DBusMessageIter value, iter;
- const char *key = "Networks";
-
- dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, &key);
-
- dbus_message_iter_open_container(entry, DBUS_TYPE_VARIANT,
- DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING,
- &value);
-
- dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
- DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
- __connman_element_list((struct connman_element *) device,
- CONNMAN_ELEMENT_TYPE_NETWORK, &iter);
- dbus_message_iter_close_container(&value, &iter);
-
- dbus_message_iter_close_container(entry, &value);
-}
-
-static void emit_networks_signal(struct connman_device *device)
-{
- const char *path = connman_device_get_path(device);
- DBusMessage *signal;
- DBusMessageIter entry;
-
- signal = dbus_message_new_signal(path,
- CONNMAN_DEVICE_INTERFACE, "PropertyChanged");
- if (signal == NULL)
- return;
-
- dbus_message_iter_init_append(signal, &entry);
-
- append_networks(device, &entry);
-
- g_dbus_send_message(connection, signal);
-}
-
-static int register_interface(struct connman_element *element)
-{
- struct connman_network *network = element->network;
-
- DBG("element %p name %s", element, element->name);
-
- if (g_dbus_register_interface(connection, element->path,
- CONNMAN_NETWORK_INTERFACE,
- network_methods, network_signals,
- NULL, network, NULL) == FALSE) {
- connman_error("Failed to register %s network", element->path);
- return -EIO;
- }
-
- network->registered = TRUE;
-
- emit_networks_signal(network->device);
-
- return 0;
-}
-
-static void unregister_interface(struct connman_element *element)
-{
- struct connman_network * network = element->network;
-
- DBG("element %p name %s", element, element->name);
-
- network->registered = FALSE;
-
- emit_networks_signal(network->device);
-
- g_dbus_unregister_interface(connection, element->path,
- CONNMAN_NETWORK_INTERFACE);
-}
-
connman_bool_t __connman_network_has_driver(struct connman_network *network)
{
if (network == NULL || network->driver == NULL)
return FALSE;
- return network->registered;
+ return TRUE;
}
static GSList *driver_list = NULL;
*/
int connman_network_driver_register(struct connman_network_driver *driver)
{
+ GSList *list;
+
DBG("driver %p name %s", driver, driver->name);
+ for (list = driver_list; list; list = list->next) {
+ struct connman_network_driver *tmp = list->data;
+
+ if (tmp->type == driver->type)
+ return -EALREADY;
+
+ }
+
driver_list = g_slist_insert_sorted(driver_list, driver,
compare_priority);
g_free(network->wifi.mode);
g_free(network->wifi.security);
g_free(network->wifi.passphrase);
+ g_free(network->wifi.eap);
+ g_free(network->wifi.identity);
+ g_free(network->wifi.ca_cert_path);
+ g_free(network->wifi.client_cert_path);
+ g_free(network->wifi.private_key_path);
+ g_free(network->wifi.private_key_passphrase);
+ g_free(network->wifi.phase2_auth);
+ g_free(network->wifi.pin_wps);
g_free(network->group);
g_free(network->node);
g_free(network->name);
- g_free(network->address);
g_free(network->identifier);
- if (network->ipconfig) {
- connman_ipconfig_unref(network->ipconfig);
- network->ipconfig = NULL;
- }
+ network->device = NULL;
}
/**
__connman_element_initialize(&network->element);
- //temp = connman_dbus_encode_string(identifier);
if (identifier == NULL) {
temp = g_strdup_printf("hidden_%d", hidden_counter++);
network->hidden = TRUE;
}
/**
- * connman_network_get_path:
- * @network: network structure
- *
- * Get path name of network
- */
-const char *connman_network_get_path(struct connman_network *network)
-{
- return network->element.path;
-}
-
-/**
* connman_network_set_index:
* @network: network structure
* @index: index number
*/
void connman_network_set_index(struct connman_network *network, int index)
{
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig;
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ goto done;
+
+ ipconfig = __connman_service_get_ip4config(service);
+
+ DBG("index %d service %p ip4config %p", network->element.index,
+ service, ipconfig);
+
+ if (network->element.index < 0 && ipconfig == NULL) {
+
+ ipconfig = __connman_service_get_ip4config(service);
+ if (ipconfig == NULL)
+ /*
+ * This is needed for plugins that havent set their
+ * ipconfig layer yet, due to not being able to get
+ * a network index prior to creating a service.
+ */
+ __connman_service_create_ip4config(service, index);
+ else
+ __connman_ipconfig_set_index(ipconfig, index);
+
+ } else {
+ /* If index changed, the index of ipconfig must be reset. */
+ if (ipconfig == NULL)
+ goto done;
+
+ __connman_ipconfig_set_index(ipconfig, index);
+ }
+
+done:
network->element.index = index;
}
}
/**
- * connman_network_set_protocol:
- * @network: network structure
- * @protocol: network protocol
- *
- * Change protocol of network
- */
-void connman_network_set_protocol(struct connman_network *network,
- enum connman_network_protocol protocol)
-{
- network->protocol = protocol;
-}
-
-/**
* connman_network_set_group:
* @network: network structure
* @group: group name
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
- case CONNMAN_NETWORK_TYPE_MBM:
- case CONNMAN_NETWORK_TYPE_HSO:
case CONNMAN_NETWORK_TYPE_WIFI:
case CONNMAN_NETWORK_TYPE_WIMAX:
break;
if (g_strcmp0(network->group, group) == 0) {
if (group != NULL)
- __connman_profile_update_network(network);
+ __connman_service_update_from_network(network);
return;
}
if (network->group != NULL) {
- __connman_profile_remove_network(network);
+ __connman_service_remove_from_network(network);
g_free(network->group);
}
network->group = g_strdup(group);
if (network->group != NULL)
- __connman_profile_add_network(network);
+ __connman_service_create_from_network(network);
}
/**
if (network->device == NULL)
return NULL;
- return __connman_device_get_ident(network->device);
+ return connman_device_get_ident(network->device);
}
connman_bool_t __connman_network_get_weakness(struct connman_network *network)
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
- case CONNMAN_NETWORK_TYPE_MBM:
- case CONNMAN_NETWORK_TYPE_HSO:
case CONNMAN_NETWORK_TYPE_WIMAX:
break;
case CONNMAN_NETWORK_TYPE_WIFI:
return FALSE;
}
-connman_bool_t __connman_network_get_connecting(struct connman_network *network)
+connman_bool_t connman_network_get_connecting(struct connman_network *network)
{
return network->connecting;
}
service = __connman_service_lookup_from_network(network);
__connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_ASSOCIATION);
+ CONNMAN_SERVICE_STATE_ASSOCIATION,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
}
return 0;
service = __connman_service_lookup_from_network(network);
__connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_FAILURE);
+ CONNMAN_SERVICE_STATE_FAILURE,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+}
+
+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_indicate_state(service,
+ CONNMAN_SERVICE_STATE_FAILURE,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+}
+
+static void set_invalid_key_error(struct connman_network *network)
+{
+ struct connman_service *service;
+
+ service = __connman_service_lookup_from_network(network);
+
+ __connman_service_indicate_error(service,
+ CONNMAN_SERVICE_ERROR_INVALID_KEY);
+}
+
+static void set_connect_error(struct connman_network *network)
+{
+ struct connman_service *service;
+
+ service = __connman_service_lookup_from_network(network);
+
+ __connman_service_indicate_error(service,
+ CONNMAN_SERVICE_ERROR_CONNECT_FAILED);
+}
+
+void connman_network_set_ipv4_method(struct connman_network *network,
+ enum connman_ipconfig_method method)
+{
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig;
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return;
+
+ ipconfig = __connman_service_get_ip4config(service);
+ if (ipconfig == NULL)
+ return;
+
+ connman_ipconfig_set_method(ipconfig, method);
+}
+
+void connman_network_set_ipv6_method(struct connman_network *network,
+ enum connman_ipconfig_method method)
+{
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig;
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return;
+
+ ipconfig = __connman_service_get_ip6config(service);
+ if (ipconfig == NULL)
+ return;
+
+ connman_ipconfig_set_method(ipconfig, method);
}
void connman_network_set_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:
case CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL:
set_associate_error(network);
break;
+ case CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL:
+ set_configure_error(network);
+ break;
+ case CONNMAN_NETWORK_ERROR_INVALID_KEY:
+ set_invalid_key_error(network);
+ break;
+ case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
+ set_connect_error(network);
+ break;
}
}
-static gboolean set_connected(gpointer user_data)
+void connman_network_clear_error(struct connman_network *network)
{
- struct connman_network *network = user_data;
struct connman_service *service;
+ DBG("network %p", network);
+
+ if (network == NULL)
+ return;
+
+ if (network->connecting == TRUE || network->associating == TRUE)
+ return;
+
service = __connman_service_lookup_from_network(network);
+ __connman_service_clear_error(service);
+}
- if (network->connected == TRUE) {
- struct connman_element *element;
- enum connman_element_type type = CONNMAN_ELEMENT_TYPE_UNKNOWN;
-
- switch (network->protocol) {
- case CONNMAN_NETWORK_PROTOCOL_UNKNOWN:
- return 0;
- case CONNMAN_NETWORK_PROTOCOL_IP:
- type = CONNMAN_ELEMENT_TYPE_DHCP;
- break;
- }
+static void set_configuration(struct connman_network *network)
+{
+ struct connman_service *service;
- __connman_device_increase_connections(network->device);
+ DBG("network %p", network);
- __connman_device_set_network(network->device, network);
+ __connman_device_increase_connections(network->device);
- connman_device_set_disconnected(network->device, FALSE);
+ __connman_device_set_network(network->device, network);
- if (network->element.ipv4.method ==
- CONNMAN_IPCONFIG_METHOD_STATIC) {
+ connman_device_set_disconnected(network->device, FALSE);
- network->connecting = FALSE;
+ service = __connman_service_lookup_from_network(network);
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_CONFIGURATION,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+}
- connman_network_set_associating(network, FALSE);
+static void dhcp_success(struct connman_network *network)
+{
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig_ipv4;
+ int err;
- __connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_READY);
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ goto err;
- return TRUE;
- }
+ connman_network_set_associating(network, FALSE);
+
+ network->connecting = FALSE;
+
+ ipconfig_ipv4 = __connman_service_get_ip4config(service);
+ err = __connman_ipconfig_address_add(ipconfig_ipv4);
+ if (err < 0)
+ goto err;
+
+ err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
+ if (err < 0)
+ goto err;
+
+ __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+
+ return;
+
+err:
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+}
+
+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)
+ return;
+
+ ipconfig_ipv4 = __connman_service_get_ip4config(service);
+ __connman_ipconfig_address_remove(ipconfig_ipv4);
+
+ __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_IDLE,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+}
+
+static void dhcp_callback(struct connman_network *network,
+ connman_bool_t success)
+{
+ DBG("success %d", success);
+
+ if (success == TRUE)
+ dhcp_success(network);
+ else
+ dhcp_failure(network);
+}
+
+static int set_connected_fixed(struct connman_network *network)
+{
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig_ipv4;
+ int err;
+
+ DBG("");
+
+ service = __connman_service_lookup_from_network(network);
+
+ ipconfig_ipv4 = __connman_service_get_ip4config(service);
+
+ set_configuration(network);
+
+ network->connecting = FALSE;
+
+ connman_network_set_associating(network, FALSE);
+
+ err = __connman_ipconfig_address_add(ipconfig_ipv4);
+ if (err < 0)
+ goto err;
+
+ err = __connman_ipconfig_gateway_add(ipconfig_ipv4);
+ if (err < 0)
+ goto err;
+
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+ return 0;
+
+err:
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+
+ return err;
+}
+
+static void set_connected_manual(struct connman_network *network)
+{
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig;
+ int err;
+
+ DBG("network %p", network);
+
+ service = __connman_service_lookup_from_network(network);
+
+ ipconfig = __connman_service_get_ip4config(service);
+
+ set_configuration(network);
- element = connman_element_create(NULL);
- if (element != NULL) {
- element->type = type;
- element->index = network->element.index;
+ err = __connman_ipconfig_address_add(ipconfig);
+ if (err < 0)
+ goto err;
- if (connman_element_register(element,
- &network->element) < 0)
- connman_element_unref(element);
+ err = __connman_ipconfig_gateway_add(ipconfig);
+ if (err < 0)
+ goto err;
- __connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_CONFIGURATION);
+ network->connecting = FALSE;
+
+ connman_network_set_associating(network, FALSE);
+
+ __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+
+ return;
+
+err:
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+ return;
+}
+
+static int set_connected_dhcp(struct connman_network *network)
+{
+ int err;
+
+ DBG("network %p", network);
+
+ set_configuration(network);
+
+ err = __connman_dhcp_start(network, dhcp_callback);
+ if (err < 0) {
+ connman_error("Can not request DHCP lease");
+ return err;
+ }
+
+ return 0;
+}
+
+static int manual_ipv6_set(struct connman_network *network,
+ struct connman_ipconfig *ipconfig_ipv6)
+{
+ struct connman_service *service;
+ int err;
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return -EINVAL;
+
+ err = __connman_ipconfig_address_add(ipconfig_ipv6);
+ if (err < 0) {
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+ return err;
+ }
+
+ /*
+ * READY state will be indicated by IPV4 setting
+ * gateway will be set by IPV4 setting
+ */
+
+ return 0;
+}
+
+static void autoconf_ipv6_set(struct connman_network *network)
+{
+ struct connman_service *service;
+ const char *nameserver = NULL;
+
+ DBG("network %p", network);
+
+ service = __connman_service_lookup_from_network(network);
+
+ __connman_device_increase_connections(network->device);
+
+ __connman_device_set_network(network->device, network);
+
+ connman_device_set_disconnected(network->device, FALSE);
+
+ connman_element_get_value(&network->element,
+ CONNMAN_PROPERTY_ID_IPV6_NAMESERVER, &nameserver);
+ if (nameserver != NULL)
+ __connman_service_nameserver_append(service, nameserver);
+
+ network->connecting = FALSE;
+
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
+}
+
+static gboolean set_connected(gpointer user_data)
+{
+ struct connman_network *network = user_data;
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig_ipv4, *ipconfig_ipv6;
+ enum connman_ipconfig_method ipv4_method, ipv6_method;
+
+ service = __connman_service_lookup_from_network(network);
+
+ ipconfig_ipv4 = __connman_service_get_ip4config(service);
+ ipconfig_ipv6 = __connman_service_get_ip6config(service);
+
+ DBG("service %p ipv4 %p ipv6 %p", service, ipconfig_ipv4,
+ ipconfig_ipv6);
+
+ ipv4_method = __connman_ipconfig_get_method(ipconfig_ipv4);
+ ipv6_method = __connman_ipconfig_get_method(ipconfig_ipv6);
+
+ DBG("method ipv4 %d ipv6 %d", ipv4_method, ipv6_method);
+ DBG("network connected %d", network->connected);
+
+ if (network->connected == TRUE) {
+ int ret;
+
+ switch (ipv6_method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ break;
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ autoconf_ipv6_set(network);
+ break;
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ ret = manual_ipv6_set(network, ipconfig_ipv6);
+ if (ret != 0) {
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+ return FALSE;
+ }
+ break;
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ break;
}
+
+ switch (ipv4_method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ return FALSE;
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ if (set_connected_fixed(network) < 0) {
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+ return FALSE;
+ }
+ return TRUE;
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ set_connected_manual(network);
+ return TRUE;
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ if (set_connected_dhcp(network) < 0) {
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+ return FALSE;
+ }
+ }
+
} else {
+ struct connman_service *service;
+
connman_element_unregister_children(&network->element);
__connman_device_set_network(network->device, NULL);
network->hidden = FALSE;
- __connman_device_decrease_connections(network->device);
+ service = __connman_service_lookup_from_network(network);
+
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_DISCONNECT,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_DISCONNECT,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
+
+ __connman_connection_gateway_remove(service);
+
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_IDLE,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
__connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_IDLE);
+ CONNMAN_SERVICE_STATE_IDLE,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
}
network->connecting = FALSE;
if ((network->connecting == TRUE || network->associating == TRUE) &&
connected == FALSE) {
- connman_element_set_error(&network->element,
- CONNMAN_ELEMENT_ERROR_CONNECT_FAILED);
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_CONNECT_FAIL);
__connman_network_disconnect(network);
}
if (network->connected == connected)
return -EALREADY;
- network->connected = connected;
-
- if (network->registered == FALSE) {
- g_idle_add(set_connected, network);
- return 0;
- }
+ if (connected == FALSE)
+ __connman_device_decrease_connections(network->device);
- connman_dbus_property_changed_basic(network->element.path,
- CONNMAN_NETWORK_INTERFACE, "Connected",
- DBUS_TYPE_BOOLEAN, &connected);
+ network->connected = connected;
set_connected(network);
if (network->driver->connect == NULL)
return -ENOSYS;
- __connman_device_disconnect(network->device);
+ if (network->device == NULL)
+ return -ENODEV;
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
+ else {
+ network->connecting = FALSE;
network->hidden = FALSE;
+ }
return err;
}
err = network->driver->disconnect(network);
if (err == 0) {
- network->connected = FALSE;
+ connman_network_set_connected(network, FALSE);
set_connected(network);
}
return err;
}
-/**
- * connman_network_set_address:
- * @network: network structure
- * @address: binary address value
- * @size: binary address length
- *
- * Set unique address value for network
- */
-int connman_network_set_address(struct connman_network *network,
- const void *address, unsigned int size)
+static int manual_ipv4_set(struct connman_network *network,
+ struct connman_ipconfig *ipconfig)
+{
+ struct connman_service *service;
+ int err;
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return -EINVAL;
+
+ err = __connman_ipconfig_address_add(ipconfig);
+ if (err < 0) {
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
+ return err;
+ }
+
+ __connman_ipconfig_gateway_add(ipconfig);
+
+ __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+
+ return 0;
+}
+
+int __connman_network_clear_ipconfig(struct connman_network *network,
+ struct connman_ipconfig *ipconfig)
{
- const unsigned char *addr_octet = address;
- char *str;
+ struct connman_service *service;
+ enum connman_ipconfig_method method;
+ enum connman_ipconfig_type type;
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return -EINVAL;
- DBG("network %p size %d", network, size);
+ method = __connman_ipconfig_get_method(ipconfig);
+ type = __connman_ipconfig_get_config_type(ipconfig);
- if (size != 6)
+ switch (method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
return -EINVAL;
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ __connman_ipconfig_address_remove(ipconfig);
+ break;
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ __connman_dhcp_stop(network);
+ break;
+ }
+
+ if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_CONFIGURATION,
+ CONNMAN_IPCONFIG_TYPE_IPV6);
+ else if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+ __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_CONFIGURATION,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+
+ return 0;
+}
- str = g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
- addr_octet[0], addr_octet[1], addr_octet[2],
- addr_octet[3], addr_octet[4], addr_octet[5]);
- if (str == NULL)
- return -ENOMEM;
+int __connman_network_set_ipconfig(struct connman_network *network,
+ struct connman_ipconfig *ipconfig_ipv4,
+ struct connman_ipconfig *ipconfig_ipv6)
+{
+ enum connman_ipconfig_method method;
+ int ret;
+
+ if (ipconfig_ipv6) {
+ method = __connman_ipconfig_get_method(ipconfig_ipv6);
- g_free(network->address);
- network->address = str;
+ switch (method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ break;
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ autoconf_ipv6_set(network);
+ break;
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ ret = manual_ipv6_set(network, ipconfig_ipv6);
+ if (ret != 0) {
+ connman_network_set_error(network,
+ CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
+ return ret;
+ }
+ break;
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ break;
+ }
+ }
- return connman_element_set_string(&network->element,
- "Address", network->address);
+ if (ipconfig_ipv4) {
+ method = __connman_ipconfig_get_method(ipconfig_ipv4);
+
+ switch (method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ return -EINVAL;
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ return manual_ipv4_set(network, ipconfig_ipv4);
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ return __connman_dhcp_start(network, dhcp_callback);
+ }
+ }
+
+ return 0;
+}
+
+int connman_network_set_ipaddress(struct connman_network *network,
+ struct connman_ipaddress *ipaddress)
+{
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig = NULL;
+
+ DBG("network %p", network);
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return -EINVAL;
+
+ ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
+ if (ipconfig == NULL)
+ return -EINVAL;
+
+ __connman_ipconfig_set_local(ipconfig, ipaddress->local);
+ __connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
+ __connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
+ __connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
+ __connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);
+
+ return 0;
+}
+
+int connman_network_set_pac(struct connman_network *network,
+ const char *pac)
+{
+ struct connman_service *service;
+
+ DBG("network %p pac %s", network, pac);
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return -EINVAL;
+
+ __connman_service_set_pac(service, pac);
+
+ return 0;
+}
+
+int connman_network_set_nameservers(struct connman_network *network,
+ const char *nameservers)
+{
+ struct connman_service *service;
+ char **nameservers_array = NULL;
+ int i;
+
+ DBG("network %p nameservers %s", network, nameservers);
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return -EINVAL;
+
+ __connman_service_nameserver_clear(service);
+
+ if (nameservers != NULL)
+ nameservers_array = g_strsplit(nameservers, " ", 0);
+
+ for (i = 0; nameservers_array[i] != NULL; i++) {
+ __connman_service_nameserver_append(service,
+ nameservers_array[i]);
+ }
+
+ g_strfreev(nameservers_array);
+
+ return 0;
+}
+
+int connman_network_set_domain(struct connman_network *network,
+ const char *domain)
+{
+ struct connman_service *service;
+
+ DBG("network %p domain %s", network, domain);
+
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ return -EINVAL;
+
+ __connman_service_set_domainname(service, domain);
+
+ return 0;
}
/**
int connman_network_set_string(struct connman_network *network,
const char *key, const char *value)
{
+ int err;
+
DBG("network %p key %s value %s", network, key, value);
if (g_strcmp0(key, "Name") == 0)
return connman_network_set_name(network, value);
- if (g_str_equal(key, "Address") == TRUE) {
- g_free(network->address);
- network->address = g_strdup(value);
- } else if (g_str_equal(key, "Node") == TRUE) {
+ if (g_str_equal(key, "Node") == TRUE) {
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.Passphrase") == TRUE) {
g_free(network->wifi.passphrase);
network->wifi.passphrase = g_strdup(value);
+ } else if (g_str_equal(key, "WiFi.EAP") == TRUE) {
+ g_free(network->wifi.eap);
+ network->wifi.eap = g_strdup(value);
+ } else if (g_str_equal(key, "WiFi.Identity") == TRUE) {
+ g_free(network->wifi.identity);
+ network->wifi.identity = g_strdup(value);
+ } else if (g_str_equal(key, "WiFi.CACertFile") == TRUE) {
+ g_free(network->wifi.ca_cert_path);
+ network->wifi.ca_cert_path = g_strdup(value);
+ } else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE) {
+ g_free(network->wifi.client_cert_path);
+ network->wifi.client_cert_path = g_strdup(value);
+ } else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE) {
+ g_free(network->wifi.private_key_path);
+ network->wifi.private_key_path = g_strdup(value);
+ } else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE) {
+ g_free(network->wifi.private_key_passphrase);
+ network->wifi.private_key_passphrase = g_strdup(value);
+ } else if (g_str_equal(key, "WiFi.Phase2") == TRUE) {
+ g_free(network->wifi.phase2_auth);
+ network->wifi.phase2_auth = g_strdup(value);
+ } else if (g_str_equal(key, "WiFi.PinWPS") == TRUE) {
+ g_free(network->wifi.pin_wps);
+ network->wifi.pin_wps = g_strdup(value);
}
- return connman_element_set_string(&network->element, key, value);
+ err = connman_element_set_string(&network->element, key, value);
+ if (err < 0)
+ return err;
+
+ if (network->driver == NULL)
+ return 0;
+
+ if (network->driver->setup)
+ return network->driver->setup(network, key);
+
+ return 0;
}
/**
{
DBG("network %p key %s", network, key);
- if (g_str_equal(key, "Address") == TRUE)
- return network->address;
- else if (g_str_equal(key, "Name") == TRUE)
+ if (g_str_equal(key, "Name") == TRUE)
return network->name;
else if (g_str_equal(key, "Node") == TRUE)
return network->node;
return network->wifi.security;
else if (g_str_equal(key, "WiFi.Passphrase") == TRUE)
return network->wifi.passphrase;
+ else if (g_str_equal(key, "WiFi.EAP") == TRUE)
+ return network->wifi.eap;
+ else if (g_str_equal(key, "WiFi.Identity") == TRUE)
+ return network->wifi.identity;
+ else if (g_str_equal(key, "WiFi.CACertFile") == TRUE)
+ return network->wifi.ca_cert_path;
+ else if (g_str_equal(key, "WiFi.ClientCertFile") == TRUE)
+ return network->wifi.client_cert_path;
+ else if (g_str_equal(key, "WiFi.PrivateKeyFile") == TRUE)
+ return network->wifi.private_key_path;
+ else if (g_str_equal(key, "WiFi.PrivateKeyPassphrase") == TRUE)
+ return network->wifi.private_key_passphrase;
+ else if (g_str_equal(key, "WiFi.Phase2") == TRUE)
+ return network->wifi.phase2_auth;
+ else if (g_str_equal(key, "WiFi.PinWPS") == TRUE)
+ return network->wifi.pin_wps;
return connman_element_get_string(&network->element, key);
}
if (g_strcmp0(key, "Roaming") == 0)
return connman_network_set_roaming(network, value);
+ else if (g_strcmp0(key, "WiFi.WPS") == 0)
+ network->wifi.wps = value;
+ else if (g_strcmp0(key, "WiFi.UseWPS") == 0)
+ network->wifi.use_wps = value;
return connman_element_set_bool(&network->element, key, value);
}
if (g_str_equal(key, "Roaming") == TRUE)
return network->roaming;
+ else if (g_str_equal(key, "WiFi.WPS") == TRUE)
+ return network->wifi.wps;
+ else if (g_str_equal(key, "WiFi.UseWPS") == TRUE)
+ return network->wifi.use_wps;
return connman_element_get_bool(&network->element, key);
}
{
DBG("network %p key %s size %d", network, key, size);
- if (g_strcmp0(key, "Address") == 0)
- return connman_network_set_address(network, data, size);
-
if (g_str_equal(key, "WiFi.SSID") == TRUE) {
g_free(network->wifi.ssid);
network->wifi.ssid = g_try_malloc(size);
network->driver_data = data;
}
+void connman_network_update(struct connman_network *network)
+{
+ switch (network->type) {
+ case CONNMAN_NETWORK_TYPE_UNKNOWN:
+ case CONNMAN_NETWORK_TYPE_VENDOR:
+ return;
+ case CONNMAN_NETWORK_TYPE_ETHERNET:
+ case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
+ case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
+ case CONNMAN_NETWORK_TYPE_CELLULAR:
+ case CONNMAN_NETWORK_TYPE_WIFI:
+ case CONNMAN_NETWORK_TYPE_WIMAX:
+ break;
+ }
+
+ if (network->group != NULL)
+ __connman_service_update_from_network(network);
+
+ return;
+}
+
static gboolean match_driver(struct connman_network *network,
struct connman_network_driver *driver)
{
{
struct connman_network *network = element->network;
GSList *list;
- int err;
DBG("element %p name %s", element, element->name);
if (network->driver == NULL)
return -ENODEV;
- err = register_interface(element);
- if (err < 0) {
- if (network->driver->remove)
- network->driver->remove(network);
- return err;
- }
-
switch (network->type) {
case CONNMAN_NETWORK_TYPE_UNKNOWN:
case CONNMAN_NETWORK_TYPE_VENDOR:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
- case CONNMAN_NETWORK_TYPE_MBM:
- case CONNMAN_NETWORK_TYPE_HSO:
case CONNMAN_NETWORK_TYPE_WIFI:
case CONNMAN_NETWORK_TYPE_WIMAX:
- if (network->group != NULL)
- __connman_profile_add_network(network);
- break;
+ if (network->group != NULL &&
+ __connman_service_create_from_network(network) == NULL)
+ return -EINVAL;
}
return 0;
case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
case CONNMAN_NETWORK_TYPE_CELLULAR:
- case CONNMAN_NETWORK_TYPE_MBM:
- case CONNMAN_NETWORK_TYPE_HSO:
case CONNMAN_NETWORK_TYPE_WIFI:
case CONNMAN_NETWORK_TYPE_WIMAX:
if (network->group != NULL) {
- __connman_profile_remove_network(network);
+ __connman_service_remove_from_network(network);
g_free(network->group);
network->group = NULL;
break;
}
- unregister_interface(element);
-
if (network->driver->remove)
network->driver->remove(network);
}
if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
return;
- if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
- return;
-
if (network->connected == FALSE)
return;
{
DBG("");
- connection = connman_dbus_get_connection();
-
return connman_driver_register(&network_driver);
}
DBG("");
connman_driver_unregister(&network_driver);
-
- dbus_connection_unref(connection);
}