diff options
author | Martin Xu <martin.xu@intel.com> | 2009-12-30 16:24:10 +0800 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-12-30 00:53:42 -0800 |
commit | fc17fb73a580904fcce7c37b5a9ec2364715f9e7 (patch) | |
tree | 971154f07343e6efaa524dc9457380e8235c1f22 | |
parent | 4373a96829d0ed1153b5c72f8ef7c9522e3b7a07 (diff) | |
download | connman-fc17fb73a580904fcce7c37b5a9ec2364715f9e7.tar.gz connman-fc17fb73a580904fcce7c37b5a9ec2364715f9e7.tar.bz2 connman-fc17fb73a580904fcce7c37b5a9ec2364715f9e7.zip |
Add method handling into function set_connected()
-rw-r--r-- | src/network.c | 104 |
1 files changed, 71 insertions, 33 deletions
diff --git a/src/network.c b/src/network.c index 226d3a7d..22626ad2 100644 --- a/src/network.c +++ b/src/network.c @@ -674,56 +674,92 @@ void connman_network_set_error(struct connman_network *network, } } -static gboolean set_connected(gpointer user_data) +static void set_connected_manual(struct connman_network *network) { - struct connman_network *network = user_data; struct connman_service *service; + DBG(""); + + __connman_device_increase_connections(network->device); + + __connman_device_set_network(network->device, network); + + connman_device_set_disconnected(network->device, FALSE); + service = __connman_service_lookup_from_network(network); - 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; - } + network->connecting = FALSE; - __connman_device_increase_connections(network->device); + connman_network_set_associating(network, FALSE); - __connman_device_set_network(network->device, network); + __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY); +} - connman_device_set_disconnected(network->device, FALSE); +static int set_connected_dhcp(struct connman_network *network) +{ + struct connman_element *element; + struct connman_service *service; + int error; - if (network->element.ipv4.method == - CONNMAN_IPCONFIG_METHOD_MANUAL) { - network->connecting = FALSE; + DBG("network %p", network); - connman_network_set_associating(network, FALSE); + if (network->protocol != CONNMAN_NETWORK_PROTOCOL_IP) + return -EINVAL; - __connman_service_indicate_state(service, - CONNMAN_SERVICE_STATE_READY); + service = __connman_service_lookup_from_network(network); - return TRUE; - } + DBG("a"); + element = connman_element_create(NULL); + if (element == NULL) + return -ENOMEM; - element = connman_element_create(NULL); - if (element != NULL) { - element->type = type; - element->index = network->element.index; + element->type = CONNMAN_ELEMENT_TYPE_DHCP; + element->index = network->element.index; - if (connman_element_register(element, - &network->element) < 0) - connman_element_unref(element); + error = connman_element_register(element, &network->element); + if (error < 0) { + connman_element_unref(element); + return error; + } + + __connman_device_increase_connections(network->device); + + __connman_device_set_network(network->device, network); + + connman_device_set_disconnected(network->device, FALSE); + + __connman_service_indicate_state(service, + CONNMAN_SERVICE_STATE_CONFIGURATION); - __connman_service_indicate_state(service, - CONNMAN_SERVICE_STATE_CONFIGURATION); + return 0; +} + +static gboolean set_connected(gpointer user_data) +{ + struct connman_network *network = user_data; + + DBG("network method %d", network->element.ipv4.method); + + if (network->connected == TRUE) { + switch (network->element.ipv4.method) { + case CONNMAN_IPCONFIG_METHOD_UNKNOWN: + case CONNMAN_IPCONFIG_METHOD_OFF: + return FALSE; + case CONNMAN_IPCONFIG_METHOD_MANUAL: + case CONNMAN_IPCONFIG_METHOD_FIXED: + 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); @@ -731,6 +767,8 @@ static gboolean set_connected(gpointer user_data) __connman_device_decrease_connections(network->device); + service = __connman_service_lookup_from_network(network); + __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_IDLE); } |