Add support for different network modes
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 25 Dec 2008 18:37:48 +0000 (19:37 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 25 Dec 2008 18:37:48 +0000 (19:37 +0100)
include/device.h
plugins/bluetooth.c
src/device.c

index 88ec0fc..a3d9ad3 100644 (file)
@@ -45,6 +45,12 @@ enum connman_device_type {
        CONNMAN_DEVICE_TYPE_VENDOR    = 42,
 };
 
+enum connman_device_mode {
+       CONNMAN_DEVICE_MODE_NO_NETWORK        = 0,
+       CONNMAN_DEVICE_MODE_SINGLE_NETWORK    = 1,
+       CONNMAN_DEVICE_MODE_MULTIPLE_NETWORKS = 2,
+};
+
 enum connman_device_policy {
        CONNMAN_DEVICE_POLICY_UNKNOWN = 0,
        CONNMAN_DEVICE_POLICY_IGNORE  = 1,
@@ -69,6 +75,9 @@ extern void connman_device_set_interface(struct connman_device *device,
                                                        const char *interface);
 extern const char *connman_device_get_interface(struct connman_device *device);
 
+extern void connman_device_set_mode(struct connman_device *device,
+                                               enum connman_device_mode mode);
+
 extern int connman_device_set_powered(struct connman_device *device,
                                                        gboolean powered);
 extern int connman_device_set_carrier(struct connman_device *device,
index 20d1391..e09a860 100644 (file)
@@ -343,6 +343,8 @@ static void add_adapter(DBusConnection *connection, const char *path)
 
        connman_device_set_interface(adapter, node);
 
+       connman_device_set_mode(adapter, CONNMAN_DEVICE_MODE_MULTIPLE_NETWORKS);
+
        if (connman_device_register(adapter) < 0) {
                connman_device_unref(adapter);
                return;
index 71e4dc2..7bda8c2 100644 (file)
@@ -31,6 +31,7 @@
 struct connman_device {
        struct connman_element element;
        enum connman_device_type type;
+       enum connman_device_mode mode;
        enum connman_device_policy policy;
        gboolean powered;
        gboolean carrier;
@@ -363,6 +364,7 @@ struct connman_device *connman_device_create(const char *node,
        device->element.destruct = device_destruct;
 
        device->type = type;
+       device->mode = CONNMAN_DEVICE_MODE_NO_NETWORK;
        device->policy = CONNMAN_DEVICE_POLICY_AUTO;
 
        return device;
@@ -472,6 +474,19 @@ const char *connman_device_get_interface(struct connman_device *device)
 }
 
 /**
+ * connman_device_set_mode:
+ * @device: device structure
+ * @mode: network mode
+ *
+ * Change network mode of device
+ */
+void connman_device_set_mode(struct connman_device *device,
+                                               enum connman_device_mode mode)
+{
+       device->mode = mode;
+}
+
+/**
  * connman_device_set_powered:
  * @device: device structure
  * @powered: powered state
@@ -523,10 +538,7 @@ int connman_device_set_carrier(struct connman_device *device,
 {
        DBG("driver %p carrier %d", device, carrier);
 
-       if (!device->driver)
-               return -EINVAL;
-
-       if (device->driver->scan)
+       if (device->mode != CONNMAN_DEVICE_MODE_NO_NETWORK)
                return -EINVAL;
 
        if (device->carrier == carrier)
@@ -569,10 +581,7 @@ int connman_device_set_scanning(struct connman_device *device,
 
        DBG("driver %p scanning %d", device, scanning);
 
-       if (!device->driver)
-               return -EINVAL;
-
-       if (!device->driver->scan)
+       if (!device->driver || !device->driver->scan)
                return -EINVAL;
 
        if (device->scanning == scanning)