Diff between 0573fc7cb121fdb771908551d2051ef7ec031478 and f2091098df5cdd512217cbfaaeda05a3f3f8adb9

Changed Files

File Additions Deletions Status
mgmt/main.c +19 -31 modified

Full Patch

diff --git a/mgmt/main.c b/mgmt/main.c
index 573cfb3..14116a1 100644
--- a/mgmt/main.c
+++ b/mgmt/main.c
@@ -334,22 +334,14 @@ static int mgmt_new_link_key(int mgmt_sk, uint16_t index,
 	return 0;
 }
 
-static void type2str(uint8_t type, char *str, size_t len)
+static const char *typestr(uint8_t type)
 {
-	switch (type) {
-	case MGMT_ADDR_BREDR:
-		strncpy(str, "BR/EDR", len);
-		break;
-	case MGMT_ADDR_LE_PUBLIC:
-		strncpy(str, "LE Public", len);
-		break;
-	case MGMT_ADDR_LE_RANDOM:
-		strncpy(str, "LE Random", len);
-		break;
-	default:
-		strncpy(str, "(unknown)", len);
-		break;
-	}
+	const char *str[] = { "BR/EDR", "LE Public", "LE Random" };
+
+	if (type <= MGMT_ADDR_LE_RANDOM)
+		return str[type];
+
+	return "(unknown)";
 }
 
 static int mgmt_connected(int mgmt_sk, uint16_t index, bool connected,
@@ -364,11 +356,10 @@ static int mgmt_connected(int mgmt_sk, uint16_t index, bool connected,
 	}
 
 	if (monitor) {
-		char addr[18], type[10];
-
+		char addr[18];
 		ba2str(&ev->bdaddr, addr);
-		type2str(ev->type, type, sizeof(type));
-		printf("hci%u %s type %s %s\n", index, addr, type, ev_name);
+		printf("hci%u %s type %s %s\n", index, addr,
+						typestr(ev->type), ev_name);
 	}
 
 	return 0;
@@ -385,12 +376,10 @@ static int mgmt_conn_failed(int mgmt_sk, uint16_t index,
 	}
 
 	if (monitor) {
-		char addr[18], type[10];
-
+		char addr[18];
 		ba2str(&ev->addr.bdaddr, addr);
-		type2str(ev->addr.type, type, sizeof(type));
 		printf("hci%u %s type %s connect failed (status 0x%02x)\n",
-						index, addr, type, ev->status);
+				index, addr, typestr(ev->addr.type), ev->status);
 	}
 
 	return 0;
@@ -442,11 +431,11 @@ static int mgmt_device_found(int mgmt_sk, uint16_t index,
 	}
 
 	if (monitor || discovery) {
-		char addr[18], type[10];
+		char addr[18];
 		ba2str(&ev->addr.bdaddr, addr);
-		type2str(ev->addr.type, type, sizeof(type));
 		printf("hci%u dev_found: %s type %s class 0x%02x%02x%02x "
-			"rssi %d eir (%s)\n", index, addr, type,
+			"rssi %d eir (%s)\n", index, addr,
+			typestr(ev->addr.type),
 			ev->dev_class[2], ev->dev_class[1], ev->dev_class[0],
 			ev->rssi, ev->eir[0] == 0 ? "no" : "yes");
 	}
@@ -1057,12 +1046,11 @@ static void con_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
 	}
 
 	for (i = 0; i < count; i++) {
-		char addr[18], type[18];
+		char addr[18];
 
 		ba2str(&rp->addr[i].bdaddr, addr);
-		type2str(rp->addr[i].type, type, sizeof(type));
 
-		printf("%s type %s\n", addr, type);
+		printf("%s type %s\n", addr, typestr(rp->addr[i].type));
 	}
 
 	exit(EXIT_SUCCESS);
@@ -1169,8 +1157,8 @@ 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) {
-		fprintf(stderr, "Pairing with %s failed with status %u\n",
-							addr, rp->status);
+		fprintf(stderr, "Pairing with %s (%s) failed with status %u\n",
+				addr, typestr(rp->addr.type), rp->status);
 		exit(EXIT_FAILURE);
 	}