From: Szymon Janc <szymon.janc@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@codecoup.pl>
Subject: [PATCH 5/9] tools/btpclient: Add initial support for GAP service
Date: Thu, 7 Dec 2017 15:21:39 +0100 [thread overview]
Message-ID: <20171207142143.27324-6-szymon.janc@codecoup.pl> (raw)
In-Reply-To: <20171207142143.27324-1-szymon.janc@codecoup.pl>
This allows to get list of supported commands and present adapters.
---
tools/btpclient.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
diff --git a/tools/btpclient.c b/tools/btpclient.c
index 3a4971eeb..e63159824 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -49,6 +49,69 @@ static struct l_queue *devices;
static char *socket_path;
static struct btp *btp;
+static bool gap_service_registered;
+
+static void btp_gap_read_commands(uint16_t index, const void *param,
+ uint16_t length, void *user_data)
+{
+ uint16_t commands = 0;
+
+ if (index != BTP_INDEX_NON_CONTROLLER) {
+ btp_send_error(btp, BTP_GAP_SERVICE, index,
+ BTP_ERROR_INVALID_INDEX);
+ return;
+ }
+
+ commands |= (1 << BTP_OP_GAP_READ_SUPPORTED_COMMANDS);
+ commands |= (1 << BTP_OP_GAP_READ_CONTROLLER_INDEX_LIST);
+
+ commands = L_CPU_TO_LE16(commands);
+
+ btp_send(btp, BTP_GAP_SERVICE, BTP_OP_GAP_READ_SUPPORTED_COMMANDS,
+ BTP_INDEX_NON_CONTROLLER, sizeof(commands), &commands);
+}
+
+static void btp_gap_read_controller_index(uint16_t index, const void *param,
+ uint16_t length, void *user_data)
+{
+ const struct l_queue_entry *entry;
+ struct btp_gap_read_index_rp *rp;
+ uint8_t cnt;
+ int i;
+
+ if (index != BTP_INDEX_NON_CONTROLLER) {
+ btp_send_error(btp, BTP_GAP_SERVICE, index,
+ BTP_ERROR_INVALID_INDEX);
+ return;
+ }
+
+ cnt = l_queue_length(adapters);
+
+ rp = l_malloc(sizeof(*rp) + cnt);
+
+ rp->num = cnt;
+
+ for (i = 0, entry = l_queue_get_entries(adapters); entry;
+ i++, entry = entry->next) {
+ struct btp_adapter *adapter = entry->data;
+
+ rp->indexes[i] = adapter->index;
+ }
+
+ btp_send(btp, BTP_GAP_SERVICE, BTP_OP_GAP_READ_CONTROLLER_INDEX_LIST,
+ BTP_INDEX_NON_CONTROLLER, sizeof(*rp) + cnt, rp);
+}
+
+static void register_gap_service(void)
+{
+ btp_register(btp, BTP_GAP_SERVICE, BTP_OP_GAP_READ_SUPPORTED_COMMANDS,
+ btp_gap_read_commands, NULL, NULL);
+
+ btp_register(btp, BTP_GAP_SERVICE,
+ BTP_OP_GAP_READ_CONTROLLER_INDEX_LIST,
+ btp_gap_read_controller_index, NULL, NULL);
+}
+
static void btp_core_read_commands(uint16_t index, const void *param,
uint16_t length, void *user_data)
{
@@ -81,6 +144,7 @@ static void btp_core_read_services(uint16_t index, const void *param,
}
services |= (1 << BTP_CORE_SERVICE);
+ services |= (1 << BTP_GAP_SERVICE);
btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_READ_SUPPORTED_SERVICES,
BTP_INDEX_NON_CONTROLLER, sizeof(services), &services);
@@ -89,24 +153,76 @@ static void btp_core_read_services(uint16_t index, const void *param,
static void btp_core_register(uint16_t index, const void *param,
uint16_t length, void *user_data)
{
+ const struct btp_core_register_cp *cp = param;
+
+ if (length < sizeof(*cp))
+ goto failed;
+
if (index != BTP_INDEX_NON_CONTROLLER) {
btp_send_error(btp, BTP_CORE_SERVICE, index,
BTP_ERROR_INVALID_INDEX);
return;
}
+ switch (cp->service_id) {
+ case BTP_GAP_SERVICE:
+ if (gap_service_registered)
+ goto failed;
+
+ register_gap_service();
+ gap_service_registered = true;
+ break;
+ case BTP_GATT_SERVICE:
+ case BTP_L2CAP_SERVICE:
+ case BTP_MESH_NODE_SERVICE:
+ case BTP_CORE_SERVICE:
+ default:
+ goto failed;
+ }
+
+ btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_REGISTER,
+ BTP_INDEX_NON_CONTROLLER, 0, NULL);
+ return;
+
+failed:
btp_send_error(btp, BTP_CORE_SERVICE, index, BTP_ERROR_FAIL);
}
static void btp_core_unregister(uint16_t index, const void *param,
uint16_t length, void *user_data)
{
+ const struct btp_core_unregister_cp *cp = param;
+
+ if (length < sizeof(*cp))
+ goto failed;
+
if (index != BTP_INDEX_NON_CONTROLLER) {
btp_send_error(btp, BTP_CORE_SERVICE, index,
BTP_ERROR_INVALID_INDEX);
return;
}
+ switch (cp->service_id) {
+ case BTP_GAP_SERVICE:
+ if (!gap_service_registered)
+ goto failed;
+
+ btp_unregister_service(btp, BTP_GAP_SERVICE);
+ gap_service_registered = false;
+ break;
+ case BTP_GATT_SERVICE:
+ case BTP_L2CAP_SERVICE:
+ case BTP_MESH_NODE_SERVICE:
+ case BTP_CORE_SERVICE:
+ default:
+ goto failed;
+ }
+
+ btp_send(btp, BTP_CORE_SERVICE, BTP_OP_CORE_UNREGISTER,
+ BTP_INDEX_NON_CONTROLLER, 0, NULL);
+ return;
+
+failed:
btp_send_error(btp, BTP_CORE_SERVICE, index, BTP_ERROR_FAIL);
}
--
2.14.3
next prev parent reply other threads:[~2017-12-07 14:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 14:21 [PATCH 0/9] Initial code for BTP client Szymon Janc
2017-12-07 14:21 ` [PATCH 1/9] shared/btp: Add initial code for library Szymon Janc
2017-12-07 14:21 ` [PATCH 2/9] tools/btpclient: Add initial code Szymon Janc
2017-12-07 14:21 ` [PATCH 3/9] shared/btp: Add definitions for GAP service Szymon Janc
2017-12-07 14:21 ` [PATCH 4/9] tools/btpclient: Store index along with adapter proxy Szymon Janc
2017-12-07 17:42 ` Luiz Augusto von Dentz
2017-12-08 10:12 ` Szymon Janc
2017-12-07 14:21 ` Szymon Janc [this message]
2017-12-07 14:21 ` [PATCH 6/9] tools/btpclient: Add initial support for read controller info command Szymon Janc
2017-12-07 14:21 ` [PATCH 7/9] tools/btpclient: Get initial values for adapter setttings Szymon Janc
2017-12-07 14:21 ` [PATCH 8/9] tools/btpclient: Add support for tracking mutable adapter settings Szymon Janc
2017-12-07 14:21 ` [PATCH 9/9] tools/btpclient: Add support for configuring " Szymon Janc
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=20171207142143.27324-6-szymon.janc@codecoup.pl \
--to=szymon.janc@codecoup.pl \
--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).