Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] tools/btmgmt: refactor of repeated scan type
@ 2015-03-12 16:38 Jakub Pawlowski
  2015-03-13 10:27 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Pawlowski @ 2015-03-12 16:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jakub Pawlowski

this patch replaces often repeated scan type with defined constants.
---
 tools/btmgmt.c | 54 +++++++++++++++++++-----------------------------------
 1 file changed, 19 insertions(+), 35 deletions(-)

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index e8f76bb..fe25874 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -58,6 +58,10 @@
 #include "src/shared/util.h"
 #include "src/shared/mgmt.h"
 
+#define SCAN_TYPE_BREDR (1 << BDADDR_BREDR)
+#define SCAN_TYPE_LE ((1 << BDADDR_LE_PUBLIC) | (1 << BDADDR_LE_RANDOM))
+#define SCAN_TYPE_DUAL (SCAN_TYPE_BREDR | SCAN_TYPE_LE)
+
 static struct mgmt *mgmt = NULL;
 static uint16_t mgmt_index = MGMT_INDEX_NONE;
 
@@ -1739,7 +1743,7 @@ static void cmd_find_service(struct mgmt *mgmt, uint16_t index, int argc,
 	uuid_t uuid;
 	uint128_t uint128;
 	uuid_t uuid128;
-	uint8_t type;
+	uint8_t type = SCAN_TYPE_DUAL;
 	int8_t rssi;
 	uint16_t count;
 	int opt;
@@ -1747,10 +1751,6 @@ static void cmd_find_service(struct mgmt *mgmt, uint16_t index, int argc,
 	if (index == MGMT_INDEX_NONE)
 		index = 0;
 
-	type = 0;
-	type |= (1 << BDADDR_BREDR);
-	type |= (1 << BDADDR_LE_PUBLIC);
-	type |= (1 << BDADDR_LE_RANDOM);
 	rssi = 127;
 	count = 0;
 
@@ -1763,14 +1763,12 @@ static void cmd_find_service(struct mgmt *mgmt, uint16_t index, int argc,
 					find_service_options, NULL)) != -1) {
 		switch (opt) {
 		case 'l':
-			type &= ~(1 << BDADDR_BREDR);
-			type |= (1 << BDADDR_LE_PUBLIC);
-			type |= (1 << BDADDR_LE_RANDOM);
+			type &= ~SCAN_TYPE_BREDR;
+			type |= SCAN_TYPE_LE;
 			break;
 		case 'b':
-			type |= (1 << BDADDR_BREDR);
-			type &= ~(1 << BDADDR_LE_PUBLIC);
-			type &= ~(1 << BDADDR_LE_RANDOM);
+			type |= SCAN_TYPE_BREDR;
+			type &= ~SCAN_TYPE_LE;
 			break;
 		case 'u':
 			if (count == MAX_UUIDS) {
@@ -1850,29 +1848,22 @@ static struct option find_options[] = {
 static void cmd_find(struct mgmt *mgmt, uint16_t index, int argc, char **argv)
 {
 	struct mgmt_cp_start_discovery cp;
-	uint8_t type;
+	uint8_t type = SCAN_TYPE_DUAL;
 	int opt;
 
 	if (index == MGMT_INDEX_NONE)
 		index = 0;
 
-	type = 0;
-	type |= (1 << BDADDR_BREDR);
-	type |= (1 << BDADDR_LE_PUBLIC);
-	type |= (1 << BDADDR_LE_RANDOM);
-
 	while ((opt = getopt_long(argc, argv, "+lbh", find_options,
 								NULL)) != -1) {
 		switch (opt) {
 		case 'l':
-			type &= ~(1 << BDADDR_BREDR);
-			type |= (1 << BDADDR_LE_PUBLIC);
-			type |= (1 << BDADDR_LE_RANDOM);
+			type &= ~SCAN_TYPE_BREDR;
+			type |= SCAN_TYPE_LE;
 			break;
 		case 'b':
-			type |= (1 << BDADDR_BREDR);
-			type &= ~(1 << BDADDR_LE_PUBLIC);
-			type &= ~(1 << BDADDR_LE_RANDOM);
+			type |= SCAN_TYPE_BREDR;
+			type &= ~SCAN_TYPE_LE;
 			break;
 		case 'h':
 			find_usage();
@@ -1930,29 +1921,22 @@ static void cmd_stop_find(struct mgmt *mgmt, uint16_t index, int argc,
 			  char **argv)
 {
 	struct mgmt_cp_stop_discovery cp;
-	uint8_t type;
+	uint8_t type = SCAN_TYPE_DUAL;
 	int opt;
 
 	if (index == MGMT_INDEX_NONE)
 		index = 0;
 
-	type = 0;
-	type |= (1 << BDADDR_BREDR);
-	type |= (1 << BDADDR_LE_PUBLIC);
-	type |= (1 << BDADDR_LE_RANDOM);
-
 	while ((opt = getopt_long(argc, argv, "+lbh", stop_find_options,
 								NULL)) != -1) {
 		switch (opt) {
 		case 'l':
-			type &= ~(1 << BDADDR_BREDR);
-			type |= (1 << BDADDR_LE_PUBLIC);
-			type |= (1 << BDADDR_LE_RANDOM);
+			type &= ~SCAN_TYPE_BREDR;
+			type |= SCAN_TYPE_LE;
 			break;
 		case 'b':
-			type |= (1 << BDADDR_BREDR);
-			type &= ~(1 << BDADDR_LE_PUBLIC);
-			type &= ~(1 << BDADDR_LE_RANDOM);
+			type |= SCAN_TYPE_BREDR;
+			type &= ~SCAN_TYPE_LE;
 			break;
 		case 'h':
 		default:
-- 
2.2.0.rc0.207.ga3a616c


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools/btmgmt: refactor of repeated scan type
  2015-03-12 16:38 [PATCH] tools/btmgmt: refactor of repeated scan type Jakub Pawlowski
@ 2015-03-13 10:27 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2015-03-13 10:27 UTC (permalink / raw)
  To: Jakub Pawlowski; +Cc: linux-bluetooth

Hi Jakub,

On Thu, Mar 12, 2015, Jakub Pawlowski wrote:
> this patch replaces often repeated scan type with defined constants.
> ---
>  tools/btmgmt.c | 54 +++++++++++++++++++-----------------------------------
>  1 file changed, 19 insertions(+), 35 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-13 10:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-12 16:38 [PATCH] tools/btmgmt: refactor of repeated scan type Jakub Pawlowski
2015-03-13 10:27 ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox