device: Return -EOPNOTSUPP if the device does not support scanning
[platform/upstream/connman.git] / src / device.c
index 29da1a1..55a6d8e 100644 (file)
@@ -306,8 +306,15 @@ int __connman_device_disable(struct connman_device *device)
 
        clear_scan_trigger(device);
 
-       if (device->network)
-               connman_network_set_connected(device->network, FALSE);
+       if (device->network) {
+               struct connman_service *service =
+                       __connman_service_lookup_from_network(device->network);
+
+               if (service != NULL)
+                       __connman_service_disconnect(service);
+               else
+                       connman_network_set_connected(device->network, FALSE);
+       }
 
        err = device->driver->disable(device);
        if (err == 0) {
@@ -532,9 +539,11 @@ struct connman_device *connman_device_create(const char *node,
  *
  * Increase reference counter of device
  */
-struct connman_device *connman_device_ref(struct connman_device *device)
+struct connman_device *connman_device_ref_debug(struct connman_device *device,
+                               const char *file, int line, const char *caller)
 {
-       DBG("%p", device);
+       DBG("%p ref %d by %s:%d:%s()", device, device->refcount + 1,
+               file, line, caller);
 
        __sync_fetch_and_add(&device->refcount, 1);
 
@@ -547,8 +556,12 @@ struct connman_device *connman_device_ref(struct connman_device *device)
  *
  * Decrease reference counter of device
  */
-void connman_device_unref(struct connman_device *device)
+void connman_device_unref_debug(struct connman_device *device,
+                               const char *file, int line, const char *caller)
 {
+       DBG("%p ref %d by %s:%d:%s()", device, device->refcount - 1,
+               file, line, caller);
+
        if (__sync_fetch_and_sub(&device->refcount, 1) != 1)
                return;
 
@@ -1158,7 +1171,7 @@ int __connman_device_request_scan(enum connman_service_type type)
        case CONNMAN_SERVICE_TYPE_GPS:
        case CONNMAN_SERVICE_TYPE_VPN:
        case CONNMAN_SERVICE_TYPE_GADGET:
-               return 0;
+               return -EOPNOTSUPP;
        case CONNMAN_SERVICE_TYPE_WIFI:
        case CONNMAN_SERVICE_TYPE_WIMAX:
                break;
@@ -1185,6 +1198,23 @@ int __connman_device_request_scan(enum connman_service_type type)
        return 0;
 }
 
+int __connman_device_request_hidden_scan(struct connman_device *device,
+                               const char *ssid, unsigned int ssid_len,
+                               const char *identity, const char *passphrase)
+{
+       DBG("device %p", device);
+
+       if (device == NULL || device->driver == NULL ||
+                       device->driver->scan_hidden == NULL)
+               return -EINVAL;
+
+       if (device->scanning == TRUE)
+               return -EALREADY;
+
+       return device->driver->scan_hidden(device, ssid, ssid_len,
+                                       identity, passphrase);
+}
+
 connman_bool_t __connman_device_isfiltered(const char *devname)
 {
        char **pattern;