Diff between b142a9eaedd672f7398034638d186f0c5e993960 and 71e8b70208698d4feca7eee8a4ca202bed763e06

Changed Files

File Additions Deletions Status
lib/mgmt.h +1 -6 modified
mgmt/main.c +14 -14 modified
plugins/mgmtops.c +10 -9 modified

Full Patch

diff --git a/lib/mgmt.h b/lib/mgmt.h
index d9e8d47..4d2ed21 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -176,7 +176,6 @@ struct mgmt_cp_disconnect {
 } __packed;
 struct mgmt_rp_disconnect {
 	struct mgmt_addr_info addr;
-	uint8_t status;
 } __packed;
 
 #define MGMT_OP_GET_CONNECTIONS		0x0015
@@ -209,7 +208,6 @@ struct mgmt_cp_pair_device {
 } __packed;
 struct mgmt_rp_pair_device {
 	struct mgmt_addr_info addr;
-	uint8_t status;
 } __packed;
 
 #define MGMT_OP_CANCEL_PAIR_DEVICE	0x001A
@@ -221,7 +219,6 @@ struct mgmt_cp_unpair_device {
 } __packed;
 struct mgmt_rp_unpair_device {
 	struct mgmt_addr_info addr;
-	uint8_t status;
 } __packed;
 
 #define MGMT_OP_USER_CONFIRM_REPLY	0x001C
@@ -230,7 +227,6 @@ struct mgmt_cp_user_confirm_reply {
 } __packed;
 struct mgmt_rp_user_confirm_reply {
 	struct mgmt_addr_info addr;
-	uint8_t status;
 } __packed;
 
 #define MGMT_OP_USER_CONFIRM_NEG_REPLY	0x001D
@@ -242,7 +238,6 @@ struct mgmt_cp_user_passkey_reply {
 } __packed;
 struct mgmt_rp_user_passkey_reply {
 	struct mgmt_addr_info addr;
-	uint8_t status;
 } __packed;
 
 #define MGMT_OP_USER_PASSKEY_NEG_REPLY	0x001F
@@ -282,7 +277,6 @@ struct mgmt_cp_confirm_name {
 } __packed;
 struct mgmt_rp_confirm_name {
 	struct mgmt_addr_info addr;
-	uint8_t status;
 } __packed;
 
 #define MGMT_OP_BLOCK_DEVICE		0x0026
@@ -298,6 +292,7 @@ struct mgmt_cp_unblock_device {
 #define MGMT_EV_CMD_COMPLETE		0x0001
 struct mgmt_ev_cmd_complete {
 	uint16_t opcode;
+	uint8_t status;
 	uint8_t data[0];
 } __packed;
 
diff --git a/mgmt/main.c b/mgmt/main.c
index c3a51c3..72791cf 100644
--- a/mgmt/main.c
+++ b/mgmt/main.c
@@ -271,7 +271,7 @@ static int mgmt_cmd_complete(int mgmt_sk, uint16_t index,
 		printf("%s complete, opcode 0x%04x len %u\n", mgmt_opstr(op),
 								op, len);
 
-	mgmt_check_pending(mgmt_sk, op, index, 0, ev->data, len);
+	mgmt_check_pending(mgmt_sk, op, index, ev->status, ev->data, len);
 
 	return 0;
 }
@@ -532,7 +532,7 @@ static void confirm_name_rsp(int mgmt_sk, uint16_t op, uint16_t id,
 	struct mgmt_rp_confirm_name *rp = rsp;
 	char addr[18];
 
-	if (status != 0) {
+	if (len == 0 && status != 0) {
 		fprintf(stderr,
 			"hci%u confirm_name failed with status 0x%02x (%s)\n",
 					id, status, mgmt_errstr(status));
@@ -548,10 +548,10 @@ static void confirm_name_rsp(int mgmt_sk, uint16_t op, uint16_t id,
 
 	ba2str(&rp->addr.bdaddr, addr);
 
-	if (rp->status != 0)
+	if (status != 0)
 		fprintf(stderr,
 			"hci%u confirm_name for %s failed: 0x%02x (%s)\n",
-			id, addr, rp->status, mgmt_errstr(status));
+			id, addr, status, mgmt_errstr(status));
 	else
 		printf("hci%u confirm_name succeeded for %s\n", id, addr);
 }
@@ -1198,7 +1198,7 @@ static void disconnect_rsp(int mgmt_sk, uint16_t op, uint16_t id,
 	struct mgmt_rp_disconnect *rp = rsp;
 	char addr[18];
 
-	if (status != 0) {
+	if (len == 0 && status != 0) {
 		fprintf(stderr, "Disconnect failed with status 0x%02x (%s)\n",
 						status, mgmt_errstr(status));
 		exit(EXIT_FAILURE);
@@ -1212,13 +1212,13 @@ static void disconnect_rsp(int mgmt_sk, uint16_t op, uint16_t id,
 
 	ba2str(&rp->addr.bdaddr, addr);
 
-	if (rp->status == 0) {
+	if (status == 0) {
 		printf("%s disconnected\n", addr);
 		exit(EXIT_SUCCESS);
 	} else {
 		fprintf(stderr,
 			"Disconnecting %s failed with status 0x%02x (%s)\n",
-				addr, rp->status, mgmt_errstr(rp->status));
+				addr, status, mgmt_errstr(status));
 		exit(EXIT_FAILURE);
 	}
 }
@@ -1400,7 +1400,7 @@ static void pair_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
 	struct mgmt_rp_pair_device *rp = rsp;
 	char addr[18];
 
-	if (status != 0) {
+	if (len == 0 && status != 0) {
 		fprintf(stderr, "Pairing failed with status 0x%02x (%s)\n",
 						status, mgmt_errstr(status));
 		exit(EXIT_FAILURE);
@@ -1413,11 +1413,11 @@ static void pair_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
 
 	ba2str(&rp->addr.bdaddr, addr);
 
-	if (rp->status != 0) {
+	if (status != 0) {
 		fprintf(stderr,
 			"Pairing with %s (%s) failed. status 0x%02x (%s)\n",
-			addr, typestr(rp->addr.type), rp->status,
-			mgmt_errstr(rp->status));
+			addr, typestr(rp->addr.type), status,
+			mgmt_errstr(status));
 		exit(EXIT_FAILURE);
 	}
 
@@ -1491,7 +1491,7 @@ static void unpair_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
 	struct mgmt_rp_unpair_device *rp = rsp;
 	char addr[18];
 
-	if (status != 0) {
+	if (len == 0 && status != 0) {
 		fprintf(stderr, "Unpair device failed. status 0x%02x (%s)\n",
 						status, mgmt_errstr(status));
 		exit(EXIT_FAILURE);
@@ -1504,10 +1504,10 @@ static void unpair_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
 
 	ba2str(&rp->addr.bdaddr, addr);
 
-	if (rp->status != 0) {
+	if (status != 0) {
 		fprintf(stderr,
 			"Unpairing %s failed. status 0x%02x (%s)\n",
-				addr, rp->status, mgmt_errstr(rp->status));
+				addr, status, mgmt_errstr(status));
 		exit(EXIT_FAILURE);
 	}
 
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 020c277..716b4ed 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -946,7 +946,8 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
 	btd_adapter_unref(adapter);
 }
 
-static void disconnect_complete(int sk, uint16_t index, void *buf, size_t len)
+static void disconnect_complete(int sk, uint16_t index, uint8_t status,
+							void *buf, size_t len)
 {
 	struct mgmt_rp_disconnect *rp = buf;
 	struct controller_info *info;
@@ -959,9 +960,8 @@ static void disconnect_complete(int sk, uint16_t index, void *buf, size_t len)
 
 	ba2str(&rp->addr.bdaddr, addr);
 
-	if (rp->status != 0) {
-		error("Disconnecting %s failed with status %u",
-							addr, rp->status);
+	if (status != 0) {
+		error("Disconnecting %s failed with status %u", addr, status);
 		return;
 	}
 
@@ -979,7 +979,8 @@ static void disconnect_complete(int sk, uint16_t index, void *buf, size_t len)
 	bonding_complete(info, &rp->addr.bdaddr, HCI_CONNECTION_TERMINATED);
 }
 
-static void pair_device_complete(int sk, uint16_t index, void *buf, size_t len)
+static void pair_device_complete(int sk, uint16_t index, uint8_t status,
+							void *buf, size_t len)
 {
 	struct mgmt_rp_pair_device *rp = buf;
 	struct controller_info *info;
@@ -992,7 +993,7 @@ static void pair_device_complete(int sk, uint16_t index, void *buf, size_t len)
 
 	ba2str(&rp->addr.bdaddr, addr);
 
-	DBG("hci%d %s pairing complete status %u", index, addr, rp->status);
+	DBG("hci%d %s pairing complete status %u", index, addr, status);
 
 	if (index > max_index) {
 		error("Unexpected index %u in pair_device complete", index);
@@ -1001,7 +1002,7 @@ static void pair_device_complete(int sk, uint16_t index, void *buf, size_t len)
 
 	info = &controllers[index];
 
-	bonding_complete(info, &rp->addr.bdaddr, rp->status);
+	bonding_complete(info, &rp->addr.bdaddr, status);
 }
 
 static void get_connections_complete(int sk, uint16_t index, void *buf,
@@ -1166,7 +1167,7 @@ static void mgmt_cmd_complete(int sk, uint16_t index, void *buf, size_t len)
 		break;
 	case MGMT_OP_DISCONNECT:
 		DBG("disconnect complete");
-		disconnect_complete(sk, index, ev->data, len);
+		disconnect_complete(sk, index, ev->status, ev->data, len);
 		break;
 	case MGMT_OP_GET_CONNECTIONS:
 		get_connections_complete(sk, index, ev->data, len);
@@ -1181,7 +1182,7 @@ static void mgmt_cmd_complete(int sk, uint16_t index, void *buf, size_t len)
 		DBG("set_io_capability complete");
 		break;
 	case MGMT_OP_PAIR_DEVICE:
-		pair_device_complete(sk, index, ev->data, len);
+		pair_device_complete(sk, index, ev->status, ev->data, len);
 		break;
 	case MGMT_OP_USER_CONFIRM_REPLY:
 		DBG("user_confirm_reply complete");