Diff between 5ec9370a76c232e69fb3708d08c136b8c8c81f4a and e783cb3c5bd2e9a7fb45741f2d6c53ac2b9f63de

Changed Files

File Additions Deletions Status
src/adapter.c +35 -0 modified
src/mgmt.c +1 -32 modified

Full Patch

diff --git a/src/adapter.c b/src/adapter.c
index 4d2d710..498391e 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -4314,6 +4314,36 @@ static void connected_callback(uint16_t index, uint16_t length,
 	eir_data_free(&eir_data);
 }
 
+static void connect_failed_callback(uint16_t index, uint16_t length,
+					const void *param, void *user_data)
+{
+	const struct mgmt_ev_connect_failed *ev = param;
+	struct btd_adapter *adapter = user_data;
+	struct btd_device *device;
+	char addr[18];
+
+	if (length < sizeof(*ev)) {
+		error("Too small connect failed event");
+		return;
+	}
+
+	ba2str(&ev->addr.bdaddr, addr);
+
+	DBG("hci%u %s status %u", index, addr, ev->status);
+
+	device = adapter_find_device(adapter, addr);
+	if (device) {
+		if (device_is_bonding(device, NULL))
+			device_bonding_failed(device, ev->status);
+		if (device_is_temporary(device))
+			adapter_remove_device(adapter, device, TRUE);
+	}
+
+	/* In the case of security mode 3 devices */
+	adapter_bonding_complete(adapter, &ev->addr.bdaddr, ev->addr.type,
+								ev->status);
+}
+
 static void read_info_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -4398,6 +4428,11 @@ static void read_info_complete(uint8_t status, uint16_t length,
 						connected_callback,
 						adapter, NULL);
 
+	mgmt_register(adapter->mgmt, MGMT_EV_CONNECT_FAILED,
+						adapter->dev_id,
+						connect_failed_callback,
+						adapter, NULL);
+
 	set_dev_class(adapter, adapter->major_class, adapter->minor_class);
 
 	set_name(adapter, btd_adapter_get_name(adapter));
diff --git a/src/mgmt.c b/src/mgmt.c
index 872c886..912f671 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -178,37 +178,6 @@ static void mgmt_new_link_key(uint16_t index, void *buf, size_t len)
 	bonding_complete(index, &ev->key.addr, 0);
 }
 
-static void mgmt_connect_failed(uint16_t index, void *buf, size_t len)
-{
-	struct mgmt_ev_connect_failed *ev = buf;
-	struct btd_adapter *adapter;
-	struct btd_device *device;
-	char addr[18];
-
-	if (len < sizeof(*ev)) {
-		error("Too small connect_failed event");
-		return;
-	}
-
-	ba2str(&ev->addr.bdaddr, addr);
-
-	DBG("hci%u %s status %u", index, addr, ev->status);
-
-	if (!get_adapter_and_device(index, &ev->addr, &adapter, &device, false))
-		return;
-
-	if (device) {
-		if (device_is_bonding(device, NULL))
-			device_bonding_failed(device, ev->status);
-		if (device_is_temporary(device))
-			adapter_remove_device(adapter, device, TRUE);
-	}
-
-	/* In the case of security mode 3 devices */
-	adapter_bonding_complete(adapter, &ev->addr.bdaddr, ev->addr.type,
-								ev->status);
-}
-
 int mgmt_pincode_reply(int index, const bdaddr_t *bdaddr, const char *pin,
 								size_t pin_len)
 {
@@ -966,7 +935,7 @@ static gboolean mgmt_event(GIOChannel *channel, GIOCondition cond,
 		DBG("device_disconnected event");
 		break;
 	case MGMT_EV_CONNECT_FAILED:
-		mgmt_connect_failed(index, buf + MGMT_HDR_SIZE, len);
+		DBG("connect_failed event");
 		break;
 	case MGMT_EV_PIN_CODE_REQUEST:
 		mgmt_pin_code_request(index, buf + MGMT_HDR_SIZE, len);