OSDN Git Service

core: Add separate functions for auto-connect kernel devices
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 30 Jun 2014 16:40:25 +0000 (18:40 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 30 Jun 2014 16:40:25 +0000 (18:40 +0200)
src/adapter.c
src/adapter.h
src/device.c

index 215f38e..30d24c3 100644 (file)
@@ -3105,23 +3105,8 @@ void adapter_connect_list_remove(struct btd_adapter *adapter,
        DBG("%s removed from %s's connect_list", device_get_path(device),
                                                        adapter->system_name);
 
-       if (kernel_bg_scan) {
-               struct mgmt_cp_remove_device cp;
-               const bdaddr_t *bdaddr;
-               uint8_t bdaddr_type;
-
-               bdaddr = device_get_address(device);
-               bdaddr_type = btd_device_get_bdaddr_type(device);
-
-               memset(&cp, 0, sizeof(cp));
-               bacpy(&cp.addr.bdaddr, bdaddr);
-               cp.addr.type = bdaddr_type;
-
-               if (mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_DEVICE,
-                                       adapter->dev_id, sizeof(cp), &cp,
-                                       NULL, NULL, NULL) > 0)
-                       return;
-       }
+       if (kernel_bg_scan)
+               return;
 
        if (!adapter->connect_list) {
                stop_passive_scanning(adapter);
@@ -3134,6 +3119,49 @@ void adapter_connect_list_remove(struct btd_adapter *adapter,
        trigger_passive_scanning(adapter);
 }
 
+void adapter_auto_connect_add(struct btd_adapter *adapter,
+                                       struct btd_device *device)
+{
+       struct mgmt_cp_add_device cp;
+       const bdaddr_t *bdaddr;
+       uint8_t bdaddr_type;
+
+       if (!kernel_bg_scan)
+               return;
+
+       bdaddr = device_get_address(device);
+       bdaddr_type = btd_device_get_bdaddr_type(device);
+
+       memset(&cp, 0, sizeof(cp));
+       bacpy(&cp.addr.bdaddr, bdaddr);
+       cp.addr.type = bdaddr_type;
+       cp.action = 0x01;
+
+       mgmt_send(adapter->mgmt, MGMT_OP_ADD_DEVICE,
+                       adapter->dev_id, sizeof(cp), &cp, NULL, NULL, NULL);
+}
+
+void adapter_auto_connect_remove(struct btd_adapter *adapter,
+                                       struct btd_device *device)
+{
+       struct mgmt_cp_remove_device cp;
+       const bdaddr_t *bdaddr;
+       uint8_t bdaddr_type;
+
+       if (!kernel_bg_scan)
+               return;
+
+       bdaddr = device_get_address(device);
+       bdaddr_type = btd_device_get_bdaddr_type(device);
+
+       memset(&cp, 0, sizeof(cp));
+       bacpy(&cp.addr.bdaddr, bdaddr);
+       cp.addr.type = bdaddr_type;
+
+       mgmt_send(adapter->mgmt, MGMT_OP_REMOVE_DEVICE,
+                       adapter->dev_id, sizeof(cp), &cp, NULL, NULL, NULL);
+}
+
 static void adapter_start(struct btd_adapter *adapter)
 {
        g_dbus_emit_property_changed(dbus_conn, adapter->path,
index f88c339..a214cf9 100644 (file)
@@ -199,6 +199,10 @@ int adapter_connect_list_add(struct btd_adapter *adapter,
                                        struct btd_device *device);
 void adapter_connect_list_remove(struct btd_adapter *adapter,
                                                struct btd_device *device);
+void adapter_auto_connect_add(struct btd_adapter *adapter,
+                                       struct btd_device *device);
+void adapter_auto_connect_remove(struct btd_adapter *adapter,
+                                       struct btd_device *device);
 
 void btd_adapter_set_oob_handler(struct btd_adapter *adapter,
                                                struct oob_handler *handler);
index 9de5e2f..23eb8aa 100644 (file)
@@ -4049,11 +4049,15 @@ static void device_set_auto_connect(struct btd_device *device, gboolean enable)
 
        DBG("%s auto connect: %d", addr, enable);
 
+       if (device->auto_connect == enable)
+               return;
+
        device->auto_connect = enable;
 
        /* Disabling auto connect */
        if (enable == FALSE) {
                adapter_connect_list_remove(device->adapter, device);
+               adapter_auto_connect_remove(device->adapter, device);
                return;
        }
 
@@ -4064,6 +4068,7 @@ static void device_set_auto_connect(struct btd_device *device, gboolean enable)
 
        /* Enabling auto connect */
        adapter_connect_list_add(device->adapter, device);
+       adapter_auto_connect_add(device->adapter, device);
 }
 
 static gboolean start_discovery(gpointer user_data)