wifi: Add support for autoscan request
[framework/connectivity/connman.git] / plugins / ethernet.c
index 4829a33..fbfff63 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2012  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
@@ -63,6 +63,8 @@ static int cable_connect(struct connman_network *network)
 {
        DBG("network %p", network);
 
+       connman_network_set_connected(network, TRUE);
+
        return 0;
 }
 
@@ -70,6 +72,8 @@ static int cable_disconnect(struct connman_network *network)
 {
        DBG("network %p", network);
 
+       connman_network_set_connected(network, FALSE);
+
        return 0;
 }
 
@@ -82,7 +86,8 @@ static struct connman_network_driver cable_driver = {
        .disconnect     = cable_disconnect,
 };
 
-static void add_network(struct connman_device *device)
+static void add_network(struct connman_device *device,
+                       struct ethernet_data *ethernet)
 {
        struct connman_network *network;
        int index;
@@ -92,15 +97,12 @@ static void add_network(struct connman_device *device)
        if (network == NULL)
                return;
 
-       connman_network_register(network);
-
        index = connman_device_get_index(device);
        connman_network_set_index(network, index);
 
        connman_network_set_name(network, "Wired");
 
        if (connman_device_add_network(device, network) < 0) {
-               connman_network_unregister(network);
                connman_network_unref(network);
                return;
        }
@@ -109,7 +111,19 @@ static void add_network(struct connman_device *device)
 
        connman_network_set_group(network, "cable");
 
-       connman_network_set_connected(network, TRUE);
+       ethernet->network = network;
+}
+
+static void remove_network(struct connman_device *device,
+                               struct ethernet_data *ethernet)
+{
+       if (ethernet->network == NULL)
+               return;
+
+       connman_device_remove_network(device, ethernet->network);
+       connman_network_unref(ethernet->network);
+
+       ethernet->network = NULL;
 }
 
 static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
@@ -132,10 +146,10 @@ static void ethernet_newlink(unsigned flags, unsigned change, void *user_data)
        if ((ethernet->flags & IFF_LOWER_UP) != (flags & IFF_LOWER_UP)) {
                if (flags & IFF_LOWER_UP) {
                        DBG("carrier on");
-                       add_network(device);
+                       add_network(device, ethernet);
                } else {
                        DBG("carrier off");
-                       connman_device_remove_all_networks(device);
+                       remove_network(device, ethernet);
                }
        }
 
@@ -173,7 +187,7 @@ static void ethernet_remove(struct connman_device *device)
 
        connman_rtnl_remove_watch(ethernet->watch);
 
-       connman_device_remove_all_networks(device);
+       remove_network(device, ethernet);
 
        g_free(ethernet);
 }
@@ -293,14 +307,35 @@ static struct connman_technology_driver tech_driver = {
        .probe                  = tech_probe,
        .remove                 = tech_remove,
        .add_interface          = tech_add_interface,
-       .remove_interface       = tech_remove_interface,
+       .remove_interface       = tech_remove_interface,
        .set_tethering          = tech_set_tethering,
 };
 
+static int eth_probe(struct connman_technology *technology)
+{
+       return 0;
+}
+
+static void eth_remove(struct connman_technology *technology)
+{
+       DBG("");
+}
+
+static struct connman_technology_driver eth_driver = {
+       .name                   = "ethernet",
+       .type                   = CONNMAN_SERVICE_TYPE_ETHERNET,
+       .probe                  = eth_probe,
+       .remove                 = eth_remove,
+};
+
 static int ethernet_init(void)
 {
        int err;
 
+       err = connman_technology_driver_register(&eth_driver);
+       if (err < 0)
+               return err;
+
        err = connman_network_driver_register(&cable_driver);
        if (err < 0)
                return err;
@@ -323,6 +358,8 @@ static int ethernet_init(void)
 
 static void ethernet_exit(void)
 {
+       connman_technology_driver_unregister(&eth_driver);
+
        connman_technology_driver_unregister(&tech_driver);
 
        connman_network_driver_unregister(&cable_driver);