From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH v2 07/10] tools/btatt: Add "find-information" command.
Date: Fri, 16 May 2014 13:14:55 -0700 [thread overview]
Message-ID: <1400271298-29769-8-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1400271298-29769-1-git-send-email-armansito@chromium.org>
Added command for the "Find Information" request. Sample run:
$ btatt -d 00:02:5B:00:15:10 -v find-information 0x0001 0xffff
att: ATT command 0x04
att: < 04 01 00 ff ff
att: > 05 01 01 00 00 28 02 00 03 28 03 00 00 2a 04 00 03 28 05 00 01 2a
Find Information response:
Format: 0x01
Information Data:
handle: 0x0001, uuid: 2800
handle: 0x0002, uuid: 2803
handle: 0x0003, uuid: 2a00
handle: 0x0004, uuid: 2803
handle: 0x0005, uuid: 2a01
---
tools/btatt.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 129 insertions(+), 2 deletions(-)
diff --git a/tools/btatt.c b/tools/btatt.c
index da1eb3d..f65f4ea 100644
--- a/tools/btatt.c
+++ b/tools/btatt.c
@@ -34,6 +34,8 @@
#include <bluetooth/l2cap.h>
#include "monitor/mainloop.h"
+#include "lib/uuid.h"
+#include "src/shared/util.h"
#include "src/shared/att.h"
#define ATT_CID 4
@@ -64,7 +66,7 @@ static void exchange_mtu_cb(uint8_t opcode, const void *param,
}
if (opcode != BT_ATT_OP_EXCHANGE_MTU_RESP) {
- fprintf(stderr, "Invalid response opcode (%u)\n", opcode);
+ fprintf(stderr, "Invalid response opcode (0x%02x)\n", opcode);
goto done;
}
@@ -132,6 +134,130 @@ static void cmd_mtu(struct bt_att *att, int argc, char **argv)
}
}
+static void find_info_cb(uint8_t opcode, const void *param,
+ uint16_t len, void *user_data)
+{
+ const struct bt_att_find_information_rsp_param *rp;
+ bt_uuid_t uuid;
+ char uuidstr[MAX_LEN_UUID_STR];
+ int pair_count, pair_size;
+ uint128_t u128;
+ const uint8_t *data_ptr;
+ int i;
+
+ if (opcode == BT_ATT_OP_ERROR_RESP) {
+ handle_error(param, len);
+ goto done;
+ }
+
+ if (opcode != BT_ATT_OP_FIND_INFORMATION_RESP) {
+ fprintf(stderr, "Invalid response opcode (0x%02x)\n", opcode);
+ goto done;
+ }
+
+ rp = param;
+
+ if (len != sizeof(*rp)) {
+ fprintf(stderr, "Invalid \"Find Information\" response length "
+ "(%u)\n", len);
+ goto done;
+ }
+
+ pair_size = 2;
+ if (rp->format == 0x01)
+ pair_size += 2;
+ else if (rp->format == 0x02)
+ pair_size += 16;
+ else {
+ fprintf(stderr, "Invalid \"Find Information\" response format "
+ "(0x%02x)\n", rp->format);
+ goto done;
+ }
+
+ pair_count = rp->length / pair_size;
+
+ printf("Find Information response:\n" "\tFormat: 0x%02x\n", rp->format);
+ printf("\tInformation Data:\n");
+
+ data_ptr = rp->information_data;
+ for (i = 0; i < pair_count; i++) {
+ printf("\t\thandle: 0x%04x", get_le16(data_ptr));
+
+ if (rp->format == 0x01) {
+ bt_uuid16_create(&uuid, get_le16(data_ptr + 2));
+ } else {
+ bswap_128(data_ptr + 2, &u128);
+ bt_uuid128_create(&uuid, u128);
+ }
+
+ bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR);
+ printf(", uuid: %s\n", uuidstr);
+
+ data_ptr += pair_size;
+ }
+
+done:
+ mainloop_quit();
+}
+
+static void find_info_usage(void)
+{
+ printf("Usage: btatt find-information <start handle> <end handle>\n");
+}
+
+static struct option find_info_options[] = {
+ { "help", 0, 0, 'h'},
+ {}
+};
+
+static void cmd_find_info(struct bt_att *att, int argc, char **argv)
+{
+ struct bt_att_find_information_req_param param;
+ uint16_t start, end;
+ int opt;
+
+ while ((opt = getopt_long(argc, argv, "+h", find_info_options,
+ NULL)) != -1) {
+ switch (opt) {
+ case 'h':
+ default:
+ find_info_usage();
+ exit(EXIT_SUCCESS);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+ optind = 0;
+
+ if (argc < 2) {
+ find_info_usage();
+ exit(EXIT_FAILURE);
+ }
+
+ start = strtol(argv[0], NULL, 0);
+ if (!start) {
+ fprintf(stderr, "Invalid start handle: %s\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ end = strtol(argv[1], NULL, 0);
+ if (!end) {
+ fprintf(stderr, "Invalid end handle: %s\n", argv[1]);
+ exit(EXIT_FAILURE);
+ }
+
+ memset(¶m, 0, sizeof(param));
+ param.start_handle = start;
+ param.end_handle = end;
+
+ if (bt_att_send_sequential(att, BT_ATT_OP_FIND_INFORMATION_REQ, ¶m,
+ sizeof(param), find_info_cb, NULL, NULL) == 0) {
+ fprintf(stderr, "Unable to send \"Find Information\" request\n");
+ exit(EXIT_FAILURE);
+ }
+}
+
static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type)
{
int sock;
@@ -186,7 +312,8 @@ static struct {
void (*func)(struct bt_att *att, int argc, char **argv);
char *doc;
} command[] = {
- { "exchange-mtu", cmd_mtu, "\"Exchange MTU\" request." },
+ { "exchange-mtu", cmd_mtu, "\"Exchange MTU\" request" },
+ { "find-information", cmd_find_info, "\"Find Information\" request" },
{ }
};
--
1.8.3.2
next prev parent reply other threads:[~2014-05-16 20:14 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 20:14 [PATCH v2 00/10] bt_att initial implementation Arman Uguray
2014-05-16 20:14 ` [PATCH v2 01/10] src/shared/att: Introduce struct bt_att Arman Uguray
2014-05-25 5:32 ` Marcel Holtmann
2014-05-28 6:07 ` Arman Uguray
2014-05-28 8:37 ` Marcel Holtmann
2014-05-28 14:00 ` Luiz Augusto von Dentz
2014-05-28 18:28 ` Marcel Holtmann
2014-05-28 18:45 ` Arman Uguray
2014-05-29 20:56 ` Luiz Augusto von Dentz
2014-05-31 5:02 ` Marcel Holtmann
2014-06-02 8:05 ` Luiz Augusto von Dentz
2014-06-02 8:32 ` Marcel Holtmann
2014-05-31 5:13 ` Marcel Holtmann
2014-05-31 7:14 ` Arman Uguray
2014-05-16 20:14 ` [PATCH v2 02/10] unit/test-att: Add unit tests for src/shared/att Arman Uguray
2014-05-25 6:03 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 03/10] tools/btatt: Add command-line tool for ATT protocol testing Arman Uguray
2014-05-25 6:10 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 04/10] tools/btatt: Add "exchange-mtu" command Arman Uguray
2014-05-25 6:16 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 05/10] src/shared/att: Add "Find Information" request and response Arman Uguray
2014-05-25 6:20 ` Marcel Holtmann
2014-05-16 20:14 ` [PATCH v2 06/10] unit/test-att: Add unit test for "Find Information" request/response Arman Uguray
2014-05-25 6:22 ` Marcel Holtmann
2014-05-16 20:14 ` Arman Uguray [this message]
2014-05-16 20:14 ` [PATCH v2 08/10] src/shared/att: Add "Find By Type Value" request and response Arman Uguray
2014-05-16 20:14 ` [PATCH v2 09/10] unit/test-att: Add unit test for "Find By Type Value" request/response Arman Uguray
2014-05-16 20:14 ` [PATCH v2 10/10] tools/btatt: Add "find-by-type-value" command Arman Uguray
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400271298-29769-8-git-send-email-armansito@chromium.org \
--to=armansito@chromium.org \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).