+ c_address = __connman_ipconfig_get_local(dhcp->ipconfig);
+ c_gateway = __connman_ipconfig_get_gateway(dhcp->ipconfig);
+ c_prefixlen = __connman_ipconfig_get_prefixlen(dhcp->ipconfig);
+
+ address = g_dhcp_client_get_address(dhcp_client);
+
+ __connman_ipconfig_set_dhcp_address(dhcp->ipconfig, address);
+ DBG("last address %s", address);
+
+#if defined TIZEN_EXT
+ int dhcp_lease_duration = g_dhcp_client_get_dhcp_lease_duration(dhcp_client);
+#endif
+
+ option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
+ if (option)
+ netmask = g_strdup(option->data);
+
+ option = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER);
+ if (option)
+ gateway = g_strdup(option->data);
+
+ prefixlen = connman_ipaddress_calc_netmask_len(netmask);
+ if (prefixlen == 255)
+ connman_warn("netmask: %s is invalid", netmask);
+
+ DBG("c_address %s", c_address);
+
+ if (g_strcmp0(address, c_address)) {
+ ip_change = true;
+ if (c_address) {
+ /* Remove old ip address */
+ __connman_ipconfig_address_remove(dhcp->ipconfig);
+ }
+ }
+ if (g_strcmp0(gateway, c_gateway)) {
+ ip_change = true;
+ if (c_gateway) {
+ /* Remove gateway ip address */
+ __connman_ipconfig_gateway_remove(dhcp->ipconfig);
+ }
+ } else if (prefixlen != c_prefixlen)
+ ip_change = true;
+
+ old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
+ __connman_ipconfig_set_method(dhcp->ipconfig,
+ CONNMAN_IPCONFIG_METHOD_DHCP);
+
+#if defined TIZEN_EXT
+ __connman_ipconfig_set_dhcp_lease_duration(dhcp->ipconfig, dhcp_lease_duration);
+#endif
+
+ /*
+ * Notify IPv4.Configuration's method moved back to DHCP.
+ *
+ * This is the case ConnMan initially set an address by using
+ * IPv4LL because DHCP failed but now we got an address from DHCP.
+ */
+ if (old_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
+ struct connman_service *service =
+ connman_service_lookup_from_network(dhcp->network);
+
+ if (service)
+ __connman_service_notify_ipv4_configuration(service);
+ }
+
+#if defined TIZEN_EXT
+ if (connman_network_get_bool(dhcp->network, "WiFi.RoamingDHCP")) {
+
+ if (ip_change)
+ connman_service_notify_reconnection(
+ connman_service_lookup_from_network(dhcp->network));
+
+ connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
+ }
+#endif
+
+ if (ip_change) {
+ __connman_ipconfig_set_local(dhcp->ipconfig, address);
+ __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
+ __connman_ipconfig_set_gateway(dhcp->ipconfig, gateway);
+ }
+
+ if (!apply_lease_available_on_network(dhcp_client, dhcp))
+ goto done;
+
+ if (ip_change)
+ dhcp_valid(dhcp);
+
+done:
+ g_free(address);
+ g_free(netmask);
+ g_free(gateway);
+}
+
+static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data)
+{
+ struct connman_dhcp *dhcp = user_data;
+ enum connman_ipconfig_method old_method;
+ char *address, *netmask;
+ unsigned char prefixlen;
+
+ DBG("IPV4LL available");
+
+ address = g_dhcp_client_get_address(ipv4ll_client);
+ netmask = g_dhcp_client_get_netmask(ipv4ll_client);
+
+ prefixlen = connman_ipaddress_calc_netmask_len(netmask);
+
+ old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
+ __connman_ipconfig_set_method(dhcp->ipconfig,
+ CONNMAN_IPCONFIG_METHOD_AUTO);
+
+ /*
+ * Notify IPv4.Configuration's method is AUTO now.
+ *
+ * This is the case DHCP failed thus ConnMan used IPv4LL to get an
+ * address. Set IPv4.Configuration method to AUTO allows user to
+ * ask for a DHCP address by setting the method again to DHCP.
+ */
+ if (old_method == CONNMAN_IPCONFIG_METHOD_DHCP) {
+ struct connman_service *service =
+ connman_service_lookup_from_network(dhcp->network);
+
+ if (service)
+ __connman_service_notify_ipv4_configuration(service);
+ }
+
+ __connman_ipconfig_set_local(dhcp->ipconfig, address);
+ __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
+ __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
+
+ dhcp_valid(dhcp);
+
+ g_free(address);
+ g_free(netmask);
+}
+
+static int dhcp_initialize(struct connman_dhcp *dhcp)
+{
+ GDHCPClient *dhcp_client;
+ GDHCPClientError error;
+ int index;
+ const char *vendor_class_id;
+
+ DBG("dhcp %p", dhcp);
+
+ index = __connman_ipconfig_get_index(dhcp->ipconfig);
+
+ dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
+ if (error != G_DHCP_CLIENT_ERROR_NONE)
+#if defined TIZEN_EXT
+ {
+ DBG("failed g_dhcp_client_new(%d), index(%d)", error, index);
+#endif
+ return -EINVAL;
+#if defined TIZEN_EXT
+ }
+#endif
+
+#if !defined TIZEN_EXT
+ if (getenv("CONNMAN_DHCP_DEBUG")) {
+#endif
+ dhcp->dhcp_debug_prefix = g_strdup_printf("DHCP index %d",
+ index);
+ g_dhcp_client_set_debug(dhcp_client, dhcp_debug,
+ dhcp->dhcp_debug_prefix);
+#if !defined TIZEN_EXT
+ }
+#endif
+
+ g_dhcp_client_set_id(dhcp_client);
+
+ if (dhcp->network) {
+ struct connman_service *service;
+ const char *hostname;
+
+ service = connman_service_lookup_from_network(dhcp->network);
+
+ hostname = __connman_service_get_hostname(service);
+ if (!hostname)
+ hostname = connman_utsname_get_hostname();
+
+ if (hostname)
+ g_dhcp_client_set_send(dhcp_client,
+ G_DHCP_HOST_NAME, hostname);
+
+ g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
+ g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
+ g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
+ g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
+ g_dhcp_client_set_request(dhcp_client, 252);
+ g_dhcp_client_set_request(dhcp_client, G_DHCP_MTU);
+ }
+
+ g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
+ g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
+
+ vendor_class_id = connman_setting_get_string("VendorClassID");
+ if (vendor_class_id)
+ g_dhcp_client_set_send(dhcp_client, G_DHCP_VENDOR_CLASS_ID,
+ vendor_class_id);
+
+ g_dhcp_client_register_event(dhcp_client,
+ G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
+ lease_available_cb, dhcp);
+
+ g_dhcp_client_register_event(dhcp_client,
+ G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp);
+
+ g_dhcp_client_register_event(dhcp_client,
+ G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp);
+
+ dhcp->dhcp_client = dhcp_client;
+
+ return 0;
+}
+
+static int dhcp_release(struct connman_dhcp *dhcp)
+{
+ DBG("dhcp %p", dhcp);
+
+ if (dhcp->timeout > 0) {
+ g_source_remove(dhcp->timeout);
+ dhcp->timeout = 0;
+ }
+
+ if (dhcp->dhcp_client) {
+ g_dhcp_client_stop(dhcp->dhcp_client);
+ g_dhcp_client_unref(dhcp->dhcp_client);
+ }
+
+ dhcp->dhcp_client = NULL;
+
+ g_free(dhcp->dhcp_debug_prefix);
+ dhcp->dhcp_debug_prefix = NULL;
+
+ ipv4ll_stop_client(dhcp);
+