Add support for automatic connection policy
[connman] / src / device.c
index eb52ff6..b4a4b0f 100644 (file)
@@ -39,6 +39,7 @@ struct connman_device {
        char *name;
        char *node;
        char *interface;
+       unsigned int connections;
 
        struct connman_device_driver *driver;
        void *driver_data;
@@ -749,6 +750,17 @@ void connman_device_unref(struct connman_device *device)
 }
 
 /**
+ * connman_device_get_name:
+ * @device: device structure
+ *
+ * Get unique name of device
+ */
+const char *connman_device_get_name(struct connman_device *device)
+{
+       return device->element.name;
+}
+
+/**
  * connman_device_get_path:
  * @device: device structure
  *
@@ -873,6 +885,15 @@ int connman_device_set_powered(struct connman_device *device,
 
        g_dbus_send_message(connection, signal);
 
+       if (powered == FALSE)
+               return 0;
+
+       if (device->policy != CONNMAN_DEVICE_POLICY_AUTO)
+               return 0;
+
+       if (device->driver->scan)
+               device->driver->scan(device);
+
        return 0;
 }
 
@@ -921,6 +942,11 @@ int connman_device_set_carrier(struct connman_device *device,
        return 0;
 }
 
+static void connect_known_network(struct connman_device *device)
+{
+       DBG("device %p", device);
+}
+
 /**
  * connman_device_set_scanning:
  * @device: device structure
@@ -961,6 +987,17 @@ int connman_device_set_scanning(struct connman_device *device,
 
        g_dbus_send_message(connection, signal);
 
+       if (scanning == TRUE)
+               return 0;
+
+       if (device->connections > 0)
+               return 0;
+
+       if (device->policy != CONNMAN_DEVICE_POLICY_AUTO)
+               return 0;
+
+       connect_known_network(device);
+
        return 0;
 }
 
@@ -1008,6 +1045,16 @@ const char *connman_device_get_string(struct connman_device *device,
        return NULL;
 }
 
+void __connman_device_increase_connections(struct connman_device *device)
+{
+       device->connections++;
+}
+
+void __connman_device_decrease_connections(struct connman_device *device)
+{
+       device->connections--;
+}
+
 /**
  * connman_device_add_network:
  * @device: device structure
@@ -1198,7 +1245,7 @@ static int device_load(struct connman_device *device)
        GKeyFile *keyfile;
        gchar *pathname, *data = NULL;
        gsize length;
-       const char *str;
+       char *str;
 
        DBG("device %p", device);
 
@@ -1225,8 +1272,10 @@ static int device_load(struct connman_device *device)
        g_free(data);
 
        str = g_key_file_get_string(keyfile, "Configuration", "Policy", NULL);
-       if (str != NULL)
+       if (str != NULL) {
                device->policy = string2policy(str);
+               g_free(str);
+       }
 
        g_key_file_free(keyfile);