From: Szymon Janc <szymon.janc@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@gmail.com>
Subject: [PATCH 13/13] input: Add support for handling sixaxis devices
Date: Mon, 25 Nov 2013 22:15:52 +0000 [thread overview]
Message-ID: <1385417752-25664-14-git-send-email-szymon.janc@gmail.com> (raw)
In-Reply-To: <1385417752-25664-1-git-send-email-szymon.janc@gmail.com>
This allows to handle incoming connection from unknown devices.
If device happens to be sixaxis input device is created after
SDP was queried and then connection is authorized.
---
profiles/input/server.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 103 insertions(+), 1 deletion(-)
diff --git a/profiles/input/server.c b/profiles/input/server.c
index 21d4562..8a50d23 100644
--- a/profiles/input/server.c
+++ b/profiles/input/server.c
@@ -63,6 +63,100 @@ static int server_cmp(gconstpointer s, gconstpointer user_data)
return bacmp(&server->src, src);
}
+struct sixaxis_data {
+ GIOChannel *chan;
+ uint16_t psm;
+};
+
+static void connect_event_cb(GIOChannel *chan, GError *err, gpointer data);
+
+static void sixaxis_sdp_cb(struct btd_device *dev, int err, void *user_data)
+{
+ struct sixaxis_data *data = user_data;
+ struct input_server *server;
+ GError *gerr = NULL;
+ const bdaddr_t *src;
+ GSList *l;
+
+ DBG("err %d (%s)", err, strerror(-err));
+
+ if (err < 0)
+ goto fail;
+
+ src = btd_adapter_get_address(device_get_adapter(dev));
+
+ l = g_slist_find_custom(servers, src, server_cmp);
+ if (!l)
+ goto fail;
+
+ server = l->data;
+
+ err = input_device_set_channel(src, device_get_address(dev),
+ data->psm, data->chan);
+ if (err < 0)
+ goto fail;
+
+ if (server->confirm) {
+ if (!bt_io_accept(server->confirm, connect_event_cb, server,
+ NULL, &gerr)) {
+ error("bt_io_accept: %s", gerr->message);
+ g_error_free(gerr);
+ goto fail;
+ }
+
+ g_io_channel_unref(server->confirm);
+ server->confirm = NULL;
+ }
+
+ g_io_channel_unref(data->chan);
+ g_free(data);
+
+ return;
+
+fail:
+ g_io_channel_shutdown(data->chan, TRUE, NULL);
+ g_io_channel_unref(data->chan);
+ g_free(data);
+}
+
+static void sixaxis_browse_sdp(const bdaddr_t *src, const bdaddr_t *dst,
+ GIOChannel *chan, uint16_t psm)
+{
+ struct btd_device *device;
+ struct sixaxis_data *data;
+
+ if (psm != L2CAP_PSM_HIDP_CTRL)
+ return;
+
+ device = btd_adapter_find_device(adapter_find(src), dst);
+ if (!device)
+ return;
+
+ data = g_new0(struct sixaxis_data, 1);
+ data->chan = g_io_channel_ref(chan);
+ data->psm = psm;
+
+ device_discover_services(device);
+ device_wait_for_svc_complete(device, sixaxis_sdp_cb, data);
+}
+
+static bool check_sixaxis(const bdaddr_t *src, const bdaddr_t *dst)
+{
+ struct btd_device *device;
+
+ device = btd_adapter_find_device(adapter_find(src), dst);
+ if (!device)
+ return false;
+
+ if (btd_device_get_vendor(device) != 0x054c)
+ return false;
+
+ if (btd_device_get_product(device) != 0x0268)
+ return false;
+
+ return true;
+}
+
static void connect_event_cb(GIOChannel *chan, GError *err, gpointer data)
{
uint16_t psm;
@@ -95,6 +189,11 @@ static void connect_event_cb(GIOChannel *chan, GError *err, gpointer data)
if (ret == 0)
return;
+ if (ret == -ENOENT && check_sixaxis(&src, &dst)) {
+ sixaxis_browse_sdp(&src, &dst, chan, psm);
+ return;
+ }
+
error("Refusing input device connect: %s (%d)", strerror(-ret), -ret);
/* Send unplug virtual cable to unknown devices */
@@ -129,6 +228,9 @@ static void auth_callback(DBusError *derr, void *user_data)
goto reject;
}
+ if (!input_device_exists(&src, &dst) && check_sixaxis(&src, &dst))
+ return;
+
if (!bt_io_accept(server->confirm, connect_event_cb, server,
NULL, &err)) {
error("bt_io_accept: %s", err->message);
@@ -175,7 +277,7 @@ static void confirm_event_cb(GIOChannel *chan, gpointer user_data)
goto drop;
}
- if (!input_device_exists(&src, &dst)) {
+ if (!input_device_exists(&src, &dst) && !check_sixaxis(&src, &dst)) {
error("Refusing connection from %s: unknown device", addr);
goto drop;
}
--
1.8.4.4
next prev parent reply other threads:[~2013-11-25 22:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-25 22:15 [PATCH 00/13] sixaxis support Szymon Janc
2013-11-25 22:12 ` Antonio Ospite
2013-11-25 22:15 ` [PATCH 01/13] core: Export some symbols from libbluetooth Szymon Janc
2013-11-25 22:15 ` [PATCH 02/13] Rename adapter_get_device to btd_adapter_get_device Szymon Janc
2013-11-25 22:15 ` [PATCH 03/13] Rename device_set_temporary to btd_device_set_temporary Szymon Janc
2013-11-25 22:15 ` [PATCH 04/13] Rename device_set_trusted to btd_device_set_trusted Szymon Janc
2013-11-25 22:15 ` [PATCH 05/13] Rename device_device_set_name to btd_device_device_set_name Szymon Janc
2013-11-25 22:15 ` [PATCH 06/13] Rename device_get_uuids to btd_device_get_uuids Szymon Janc
2013-11-25 22:15 ` [PATCH 07/13] Rename adapter_get_address to btd_adapter_get_address Szymon Janc
2013-11-25 22:15 ` [PATCH 08/13] Rename adapter_find_device to btd_adapter_find_device Szymon Janc
2013-11-25 22:15 ` [PATCH 09/13] plugins: Add initial code for sixaxis plugin Szymon Janc
2013-11-25 22:15 ` [PATCH 10/13] plugins/sixaxis: Add initial code for udev handling Szymon Janc
2013-11-25 22:15 ` [PATCH 11/13] plugins/sixaxis: Add support for configuring new controllers Szymon Janc
2013-11-25 22:15 ` [PATCH 12/13] device: Add device_discover_services function Szymon Janc
2013-11-25 22:15 ` Szymon Janc [this message]
2013-11-27 9:34 ` [PATCH 00/13] sixaxis support Johan Hedberg
2013-11-27 10:01 ` Bastien Nocera
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=1385417752-25664-14-git-send-email-szymon.janc@gmail.com \
--to=szymon.janc@gmail.com \
--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