connman_uint8_t strength;
connman_uint16_t frequency;
char *identifier;
- char *address;
char *name;
char *node;
char *group;
g_free(network->group);
g_free(network->node);
g_free(network->name);
- g_free(network->address);
g_free(network->identifier);
network->device = NULL;
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);
}
/**
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;
}
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;
- network->element.ipv4.method = method;
-
service = __connman_service_lookup_from_network(network);
if (service == NULL)
return;
struct connman_service *service;
struct connman_ipconfig *ipconfig;
- network->element.ipv6.method = method;
-
service = __connman_service_lookup_from_network(network);
if (service == NULL)
return;
case CONNMAN_NETWORK_ERROR_INVALID_KEY:
set_invalid_key_error(network);
break;
+ case CONNMAN_NETWORK_ERROR_CONNECT_FAIL:
+ set_connect_error(network);
+ break;
}
}
CONNMAN_IPCONFIG_TYPE_IPV4);
}
-static int set_connected_fixed(struct connman_network *network)
+static void dhcp_success(struct connman_network *network)
{
struct connman_service *service;
- struct connman_element *parent, *element;
+ struct connman_ipconfig *ipconfig_ipv4;
+ int err;
- DBG("");
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
+ goto err;
+
+ 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;
- parent = connman_network_get_element(network);
+ ipconfig_ipv4 = __connman_service_get_ip4config(service);
+ __connman_ipconfig_address_remove(ipconfig_ipv4);
- set_configuration(network);
+ __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_IDLE,
+ CONNMAN_IPCONFIG_TYPE_IPV4);
+}
- if (parent->ipv4.address == NULL)
- return -EINVAL;
+static void dhcp_callback(struct connman_network *network,
+ connman_bool_t success)
+{
+ DBG("success %d", success);
- if (parent->ipv4.netmask == NULL)
- return -EINVAL;
+ if (success == TRUE)
+ dhcp_success(network);
+ else
+ dhcp_failure(network);
+}
- element = connman_element_create(NULL);
- if (element == NULL) {
- connman_error("Can not create connman_element");
- return -ENOMEM;
- }
+static int set_connected_fixed(struct connman_network *network)
+{
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig_ipv4;
+ int err;
- element->type = CONNMAN_ELEMENT_TYPE_IPV4;
- element->index = parent->index;
+ DBG("");
- if (connman_element_register(element, parent) < 0) {
- connman_error("Can not register connman_element");
- return -EINVAL;
- }
+ 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;
- const char *nameserver = NULL;
int err;
DBG("network %p", network);
set_configuration(network);
- err = __connman_ipconfig_set_address(ipconfig);
- if (err < 0) {
- connman_network_set_error(network,
- CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
- return;
- }
-
- connman_element_get_value(&network->element,
- CONNMAN_PROPERTY_ID_IPV4_NAMESERVER, &nameserver);
- if (nameserver != NULL)
- __connman_service_append_nameserver(service, nameserver);
+ err = __connman_ipconfig_address_add(ipconfig);
+ if (err < 0)
+ goto err;
- __connman_ipconfig_set_gateway(ipconfig, &network->element);
+ err = __connman_ipconfig_gateway_add(ipconfig);
+ if (err < 0)
+ goto err;
network->connecting = 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)
{
- struct connman_element *element;
- int error;
+ int err;
DBG("network %p", network);
- element = connman_element_create(NULL);
- if (element == NULL)
- return -ENOMEM;
-
- element->type = CONNMAN_ELEMENT_TYPE_DHCP;
- element->index = network->element.index;
+ set_configuration(network);
- error = connman_element_register(element, &network->element);
- if (error < 0) {
- connman_element_unref(element);
- return error;
+ err = __connman_dhcp_start(network, dhcp_callback);
+ if (err < 0) {
+ connman_error("Can not request DHCP lease");
+ return err;
}
- set_configuration(network);
-
return 0;
}
if (service == NULL)
return -EINVAL;
- err = __connman_ipconfig_set_address(ipconfig_ipv6);
+ err = __connman_ipconfig_address_add(ipconfig_ipv6);
if (err < 0) {
connman_network_set_error(network,
CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
return 0;
}
-static void autoconf_ipv6_set(struct connman_network *network,
- struct connman_ipconfig *ipconfig_ipv6)
+static void autoconf_ipv6_set(struct connman_network *network)
{
struct connman_service *service;
- struct connman_ipconfig *ipconfig;
const char *nameserver = NULL;
DBG("network %p", network);
service = __connman_service_lookup_from_network(network);
- ipconfig = __connman_service_get_ip6config(service);
-
__connman_device_increase_connections(network->device);
__connman_device_set_network(network->device, network);
connman_element_get_value(&network->element,
CONNMAN_PROPERTY_ID_IPV6_NAMESERVER, &nameserver);
if (nameserver != NULL)
- __connman_service_append_nameserver(service, nameserver);
+ __connman_service_nameserver_append(service, nameserver);
network->connecting = FALSE;
case CONNMAN_IPCONFIG_METHOD_OFF:
break;
case CONNMAN_IPCONFIG_METHOD_AUTO:
- autoconf_ipv6_set(network, ipconfig_ipv6);
+ autoconf_ipv6_set(network);
break;
case CONNMAN_IPCONFIG_METHOD_FIXED:
case CONNMAN_IPCONFIG_METHOD_MANUAL:
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);
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);
}
*/
int __connman_network_connect(struct connman_network *network)
{
- struct connman_service *service;
int err;
DBG("network %p", network);
__connman_device_disconnect(network->device);
- service = __connman_service_lookup_from_network(network);
-
err = network->driver->connect(network);
if (err < 0) {
if (err == -EINPROGRESS)
return err;
}
-static int dhcp_start(struct connman_network *network)
-{
- struct connman_element *element;
- int error;
-
- element = connman_element_create(NULL);
- if (element == NULL)
- return -ENOMEM;
-
- element->type = CONNMAN_ELEMENT_TYPE_DHCP;
- element->index = network->element.index;
-
- error = connman_element_register(element, &network->element);
- if (error < 0) {
- connman_element_unref(element);
- return error;
- }
-
- return 0;
-}
-
-static int dhcp_stop(struct connman_network *network)
-{
- connman_element_unregister_children_type(&network->element,
- CONNMAN_ELEMENT_TYPE_CONNECTION);
- connman_element_unregister_children_type(&network->element,
- CONNMAN_ELEMENT_TYPE_IPV4);
- connman_element_unregister_children_type(&network->element,
- CONNMAN_ELEMENT_TYPE_DHCP);
-
- return 0;
-}
-
static int manual_ipv4_set(struct connman_network *network,
struct connman_ipconfig *ipconfig)
{
if (service == NULL)
return -EINVAL;
- err = __connman_ipconfig_set_address(ipconfig);
+ err = __connman_ipconfig_address_add(ipconfig);
if (err < 0) {
connman_network_set_error(network,
CONNMAN_NETWORK_ERROR_CONFIGURE_FAIL);
return err;
}
- __connman_ipconfig_set_gateway(ipconfig, &network->element);
+ __connman_ipconfig_gateway_add(ipconfig);
__connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY,
CONNMAN_IPCONFIG_TYPE_IPV4);
case CONNMAN_IPCONFIG_METHOD_AUTO:
return -EINVAL;
case CONNMAN_IPCONFIG_METHOD_MANUAL:
- connman_element_unregister_children_type(&network->element,
- CONNMAN_ELEMENT_TYPE_CONNECTION);
- __connman_ipconfig_clear_address(ipconfig);
+ __connman_ipconfig_address_remove(ipconfig);
break;
case CONNMAN_IPCONFIG_METHOD_DHCP:
- dhcp_stop(network);
+ __connman_dhcp_stop(network);
break;
}
case CONNMAN_IPCONFIG_METHOD_OFF:
break;
case CONNMAN_IPCONFIG_METHOD_AUTO:
- autoconf_ipv6_set(network, ipconfig_ipv6);
+ autoconf_ipv6_set(network);
break;
case CONNMAN_IPCONFIG_METHOD_FIXED:
case CONNMAN_IPCONFIG_METHOD_MANUAL:
if (ret != 0) {
connman_network_set_error(network,
CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
- return FALSE;
+ return ret;
}
break;
case CONNMAN_IPCONFIG_METHOD_DHCP:
case CONNMAN_IPCONFIG_METHOD_MANUAL:
return manual_ipv4_set(network, ipconfig_ipv4);
case CONNMAN_IPCONFIG_METHOD_DHCP:
- return dhcp_start(network);
+ return __connman_dhcp_start(network, dhcp_callback);
}
}
return 0;
}
-/**
- * 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)
+int connman_network_set_ipaddress(struct connman_network *network,
+ struct connman_ipaddress *ipaddress)
{
- const unsigned char *addr_octet = address;
- char *str;
+ struct connman_service *service;
+ struct connman_ipconfig *ipconfig = NULL;
- DBG("network %p size %d", network, size);
+ DBG("network %p", network);
- if (size != 6)
+ service = __connman_service_lookup_from_network(network);
+ if (service == NULL)
return -EINVAL;
- 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;
+ ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
+ if (ipconfig == NULL)
+ return -EINVAL;
- g_free(network->address);
- network->address = str;
+ __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 connman_element_set_string(&network->element,
- "Address", network->address);
+ 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;
}
/**
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) {
{
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;
{
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);
case CONNMAN_NETWORK_TYPE_CELLULAR:
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_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;
if (element->state != CONNMAN_ELEMENT_STATE_ERROR)
return;
- if (element->error != CONNMAN_ELEMENT_ERROR_DHCP_FAILED)
- return;
-
if (network->connected == FALSE)
return;