All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] tools/sdptool: Fix search for UUID128
@ 2015-01-06 22:32 Jeroen Sack
  2015-01-06 22:32 ` [PATCH 2/3] tools/sdptool: Fix UUID128 format in tree output Jeroen Sack
  2015-01-06 22:32 ` [PATCH 3/3] tools/hciconfig: Display UUID32 and UUID128 EIR data Jeroen Sack
  0 siblings, 2 replies; 3+ messages in thread
From: Jeroen Sack @ 2015-01-06 22:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jeroen Sack

When running sdptool search with an UUID128 it will give
a segmentation fault, this patch will make it work.

I think it would be better to do via uuid-helper.c, but
the names in uuid-helper are different from the ones
in sdptool.
---
 tools/sdptool.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/tools/sdptool.c b/tools/sdptool.c
index 17561b1..a65fc95 100644
--- a/tools/sdptool.c
+++ b/tools/sdptool.c
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <getopt.h>
+#include <stdbool.h>
 #include <sys/socket.h>
 
 #include <bluetooth/bluetooth.h>
@@ -67,6 +68,15 @@ static int estr2ba(char *str, bdaddr_t *ba)
 	return str2ba(str, ba);
 }
 
+static inline bool is_uuid128(const char *string)
+{
+	return (strlen(string) == 36 &&
+			string[8] == '-' &&
+			string[13] == '-' &&
+			string[18] == '-' &&
+			string[23] == '-');
+}
+
 #define DEFAULT_VIEW	0	/* Display only known attribute */
 #define TREE_VIEW	1	/* Display full attribute tree */
 #define RAW_VIEW	2	/* Display raw tree */
@@ -4038,6 +4048,7 @@ static int cmd_search(int argc, char **argv)
 {
 	struct search_context context;
 	unsigned char *uuid = NULL;
+	unsigned char uuid128[16];
 	uint32_t class = 0;
 	bdaddr_t bdaddr;
 	int has_addr = 0;
@@ -4085,6 +4096,30 @@ static int cmd_search(int argc, char **argv)
 		sscanf(context.svc + 2, "%X", &num);
 		class = num;
 		printf("Class 0x%X\n", class);
+	} else if(is_uuid128(context.svc)) {
+		/* This is a UUID128, so convert it to raw data
+		 * and put it in uuid pointer */
+		uint32_t data0, data4;
+		uint16_t data1, data2, data3, data5;
+
+		uuid = uuid128;
+
+		if(sscanf(context.svc, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
+		          &data0, &data1, &data2, &data3, &data4, &data5) == 6) {
+			data0 = htonl(data0);
+			data1 = htons(data1);
+			data2 = htons(data2);
+			data3 = htons(data3);
+			data4 = htonl(data4);
+			data5 = htons(data5);
+
+			memcpy(&uuid[0], &data0, 4);
+			memcpy(&uuid[4], &data1, 2);
+			memcpy(&uuid[6], &data2, 2);
+			memcpy(&uuid[8], &data3, 2);
+			memcpy(&uuid[10], &data4, 4);
+			memcpy(&uuid[14], &data5, 2);
+		}
 	} else {
 		/* Convert class name to an UUID */
 
-- 
2.1.4


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

* [PATCH 2/3] tools/sdptool: Fix UUID128 format in tree output
  2015-01-06 22:32 [PATCH 1/3] tools/sdptool: Fix search for UUID128 Jeroen Sack
@ 2015-01-06 22:32 ` Jeroen Sack
  2015-01-06 22:32 ` [PATCH 3/3] tools/hciconfig: Display UUID32 and UUID128 EIR data Jeroen Sack
  1 sibling, 0 replies; 3+ messages in thread
From: Jeroen Sack @ 2015-01-06 22:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jeroen Sack

Write UUID128 in format used in the rest of the code when
showing sdp records in tree format.

---
 tools/sdptool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/sdptool.c b/tools/sdptool.c
index a65fc95..8057551 100644
--- a/tools/sdptool.c
+++ b/tools/sdptool.c
@@ -445,7 +445,7 @@ static void sdp_uuid_printf(uuid_t *uuid, struct attrib_context *context, int in
 			memcpy(&data4, &uuid->value.uuid128.data[10], 4);
 			memcpy(&data5, &uuid->value.uuid128.data[14], 2);
 
-			printf("%.*sUUID128 : 0x%.8x-%.4x-%.4x-%.4x-%.8x-%.4x\n",
+			printf("%.*sUUID128 : %.8x-%.4x-%.4x-%.4x-%.8x%.4x\n",
 				indent, indent_spaces,
 				ntohl(data0), ntohs(data1), ntohs(data2),
 				ntohs(data3), ntohl(data4), ntohs(data5));
-- 
2.1.4


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

* [PATCH 3/3] tools/hciconfig: Display UUID32 and UUID128 EIR data
  2015-01-06 22:32 [PATCH 1/3] tools/sdptool: Fix search for UUID128 Jeroen Sack
  2015-01-06 22:32 ` [PATCH 2/3] tools/sdptool: Fix UUID128 format in tree output Jeroen Sack
@ 2015-01-06 22:32 ` Jeroen Sack
  1 sibling, 0 replies; 3+ messages in thread
From: Jeroen Sack @ 2015-01-06 22:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jeroen Sack

Add support for UUID32 and UUID128 to hciconfig
<interface> inqdata command.

---
 tools/hciconfig.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 17c740b..f7dcd34 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -1285,6 +1285,7 @@ static void cmd_inq_data(int ctl, int hdev, char *opt)
 		}
 	} else {
 		uint8_t fec, data[HCI_MAX_EIR_LENGTH], len, type, *ptr;
+		int spaceCount;
 		char *str;
 
 		if (hci_read_ext_inquiry_response(dd, &fec, data, 1000) < 0) {
@@ -1312,7 +1313,7 @@ static void cmd_inq_data(int ctl, int hdev, char *opt)
 				break;
 			case 0x02:
 			case 0x03:
-				printf("\t%s service classes:",
+				printf("\t%s UUID16 service classes:",
 					type == 0x02 ? "Shortened" : "Complete");
 				for (i = 0; i < (len - 1) / 2; i++) {
 					uint16_t val = get_le16((ptr + (i * 2)));
@@ -1320,6 +1321,38 @@ static void cmd_inq_data(int ctl, int hdev, char *opt)
 				}
 				printf("\n");
 				break;
+			case 0x04:
+			case 0x05:
+				printf("\t%s UUID32 service classes: ",
+					type == 0x04 ? "Shortened" : "Complete");
+				for (i = 0; i < (len - 1) / 4; i++) {
+					uint32_t val = get_le32((ptr + (i * 4)));
+					printf(" 0x%8.8x", val);
+				}
+				printf("\n");
+				break;
+			case 0x06:
+			case 0x07:
+				printf("\t%s UUID128 service classes: %n",
+					(type == 0x06 ? "Shortened" : "Complete"),
+					&spaceCount);
+				for (i = 0; i < (len - 1) / 16; i++) {
+					if(i != 0) {
+						/*print tab and same amount of spaces
+						 *as characters used in previous line*/
+						printf("\t%*s", spaceCount - 1, "");
+					}
+					uint32_t data0 = get_le32((ptr + (i * 16) + 12));
+					uint16_t data1 = get_le16((ptr + (i * 16) + 10));
+					uint16_t data2 = get_le16((ptr + (i * 16) + 8));
+					uint16_t data3 = get_le16((ptr + (i * 16) + 6));
+					uint32_t data4 = get_le32((ptr + (i * 16) + 2));
+					uint16_t data5 = get_le16((ptr + (i * 16) + 0));
+
+					printf("%.8x-%.4x-%.4x-%.4x-%.8x%.4x\n",
+					       data0, data1, data2, data3, data4, data5);
+				}
+				break;
 			case 0x08:
 			case 0x09:
 				str = malloc(len);
-- 
2.1.4


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

end of thread, other threads:[~2015-01-06 22:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-06 22:32 [PATCH 1/3] tools/sdptool: Fix search for UUID128 Jeroen Sack
2015-01-06 22:32 ` [PATCH 2/3] tools/sdptool: Fix UUID128 format in tree output Jeroen Sack
2015-01-06 22:32 ` [PATCH 3/3] tools/hciconfig: Display UUID32 and UUID128 EIR data Jeroen Sack

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.