2013-11-25 22:15:39

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 00/13] sixaxis support

Hi All,

This is yet another attempt to get PS3 controller support into BlueZ upstream.

I based my work on Fedora out-of-tree patch (hence copyright info) and tried
to take into consideration comments from previous upstreaming attempt.

I find sixaxis name short and neat so I sticked with it.

I didn't really like the idea of hardcoding SDP records so I took different
approach of doing reverse SDP search while cable associated device first
connects. This is done before authorizing incoming HID connection.

Some functions unavailable to exteral plugins were renamed with btd_ prefix
(or explicitly marked in bletooth.ver) to export them (patch 1-8).

Patch 9-10 add sixaxis external plugin that depends on udev. This plugin is
responsible for preparing newly USB connected PS3 sixaxis device and creating
btd_device with proper PNP information.

Patch 12 adds support for handling first connection of sixaxis device in input
plugin itself. This is something I would like to get comments and suggestions.
Currently this is rather sixaxis oriented, but could be made more generic (some
hooks registration) if desired.

This serie is not implemententing any LED (or other features) setting support.
I have an impression that those should not be handled by BlueZ but some other
entity (util tools or driver itself perhabs?) as this is not related to
transport itself and should be set/used on USB connection as well.

This was tested with Dualshock3 and seems to be working nicely here.

Comments are welcome.

--
BR
Szymon Janc

Szymon Janc (13):
core: Export some symbols from libbluetooth
Rename adapter_get_device to btd_adapter_get_device
Rename device_set_temporary to btd_device_set_temporary
Rename device_set_trusted to btd_device_set_trusted
Rename device_device_set_name to btd_device_device_set_name
Rename device_get_uuids to btd_device_get_uuids
Rename adapter_get_address to btd_adapter_get_address
Rename adapter_find_device to btd_adapter_find_device
plugins: Add initial code for sixaxis plugin
plugins/sixaxis: Add initial code for udev handling
plugins/sixaxis: Add support for configuring new controllers
device: Add device_discover_services function
input: Add support for handling sixaxis devices

Makefile.plugins | 8 ++
bootstrap-configure | 1 +
configure.ac | 5 +
plugins/neard.c | 10 +-
plugins/sixaxis.c | 286 ++++++++++++++++++++++++++++++++++++++++++
plugins/wiimote.c | 2 +-
profiles/audio/avctp.c | 18 +--
profiles/audio/avdtp.c | 11 +-
profiles/health/hdp.c | 10 +-
profiles/health/hdp_util.c | 6 +-
profiles/input/device.c | 4 +-
profiles/input/manager.c | 4 +-
profiles/input/server.c | 104 ++++++++++++++-
profiles/network/connection.c | 2 +-
profiles/network/server.c | 4 +-
profiles/sap/server.c | 3 +-
src/adapter.c | 74 ++++++-----
src/adapter.h | 6 +-
src/attrib-server.c | 6 +-
src/bluetooth.ver | 2 +
src/device.c | 70 +++++++----
src/device.h | 10 +-
src/profile.c | 14 +--
23 files changed, 551 insertions(+), 109 deletions(-)
create mode 100644 plugins/sixaxis.c

--
1.8.4.4



2013-11-27 10:01:59

by Bastien Nocera

[permalink] [raw]
Subject: Re: [PATCH 00/13] sixaxis support

On Wed, 2013-11-27 at 11:34 +0200, Johan Hedberg wrote:
<snip>
> This looked good enough to me, so all patches have been applied. Thanks.
>
> I did apply one small patch on top of this though to make the include
> statements consistent with the direction we're trying to push the tree
> in.

\o/

Only took a few years :)


2013-11-27 09:34:15

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 00/13] sixaxis support

Hi Szymon,

On Mon, Nov 25, 2013, Szymon Janc wrote:
> Hi All,
>
> This is yet another attempt to get PS3 controller support into BlueZ upstream.
>
> I based my work on Fedora out-of-tree patch (hence copyright info) and tried
> to take into consideration comments from previous upstreaming attempt.
>
> I find sixaxis name short and neat so I sticked with it.
>
> I didn't really like the idea of hardcoding SDP records so I took different
> approach of doing reverse SDP search while cable associated device first
> connects. This is done before authorizing incoming HID connection.
>
> Some functions unavailable to exteral plugins were renamed with btd_ prefix
> (or explicitly marked in bletooth.ver) to export them (patch 1-8).
>
> Patch 9-10 add sixaxis external plugin that depends on udev. This plugin is
> responsible for preparing newly USB connected PS3 sixaxis device and creating
> btd_device with proper PNP information.
>
> Patch 12 adds support for handling first connection of sixaxis device in input
> plugin itself. This is something I would like to get comments and suggestions.
> Currently this is rather sixaxis oriented, but could be made more generic (some
> hooks registration) if desired.
>
> This serie is not implemententing any LED (or other features) setting support.
> I have an impression that those should not be handled by BlueZ but some other
> entity (util tools or driver itself perhabs?) as this is not related to
> transport itself and should be set/used on USB connection as well.
>
> This was tested with Dualshock3 and seems to be working nicely here.
>
> Comments are welcome.
>
> --
> BR
> Szymon Janc
>
> Szymon Janc (13):
> core: Export some symbols from libbluetooth
> Rename adapter_get_device to btd_adapter_get_device
> Rename device_set_temporary to btd_device_set_temporary
> Rename device_set_trusted to btd_device_set_trusted
> Rename device_device_set_name to btd_device_device_set_name
> Rename device_get_uuids to btd_device_get_uuids
> Rename adapter_get_address to btd_adapter_get_address
> Rename adapter_find_device to btd_adapter_find_device
> plugins: Add initial code for sixaxis plugin
> plugins/sixaxis: Add initial code for udev handling
> plugins/sixaxis: Add support for configuring new controllers
> device: Add device_discover_services function
> input: Add support for handling sixaxis devices
>
> Makefile.plugins | 8 ++
> bootstrap-configure | 1 +
> configure.ac | 5 +
> plugins/neard.c | 10 +-
> plugins/sixaxis.c | 286 ++++++++++++++++++++++++++++++++++++++++++
> plugins/wiimote.c | 2 +-
> profiles/audio/avctp.c | 18 +--
> profiles/audio/avdtp.c | 11 +-
> profiles/health/hdp.c | 10 +-
> profiles/health/hdp_util.c | 6 +-
> profiles/input/device.c | 4 +-
> profiles/input/manager.c | 4 +-
> profiles/input/server.c | 104 ++++++++++++++-
> profiles/network/connection.c | 2 +-
> profiles/network/server.c | 4 +-
> profiles/sap/server.c | 3 +-
> src/adapter.c | 74 ++++++-----
> src/adapter.h | 6 +-
> src/attrib-server.c | 6 +-
> src/bluetooth.ver | 2 +
> src/device.c | 70 +++++++----
> src/device.h | 10 +-
> src/profile.c | 14 +--
> 23 files changed, 551 insertions(+), 109 deletions(-)
> create mode 100644 plugins/sixaxis.c

This looked good enough to me, so all patches have been applied. Thanks.

I did apply one small patch on top of this though to make the include
statements consistent with the direction we're trying to push the tree
in.

Johan

2013-11-25 22:12:34

by Antonio Ospite

[permalink] [raw]
Subject: Re: [PATCH 00/13] sixaxis support

On Mon, 25 Nov 2013 22:15:39 +0000
Szymon Janc <[email protected]> wrote:

> Hi All,
>
> This is yet another attempt to get PS3 controller support into BlueZ upstream.
>
> I based my work on Fedora out-of-tree patch (hence copyright info) and tried
> to take into consideration comments from previous upstreaming attempt.
>

Hi Szymon, JFYI the latest patch for my playstation-peripheral plugin
is here:
http://ao2.it/tmp/playstation-peripheral-pugin-v5.x-2013-11-13.patch

Only two patches to BlueZ should be needed with this code.

Basically the only show-stopper was a way to add a device to the
database before it ever connects, I went for this
"btd_create_stored_device(everything_we_know)" but BlueZ devs didn't
like this "kitchen sink" function.

>From my POV the problem here was:
"Add a known device to the device database before it ever connects"

However it looks like I didn't get to solve it in an acceptable way.

> I find sixaxis name short and neat so I sticked with it.
>

I was using playstation-peripheral thinking to the PS Move and
possibly other devices which may work slightly different.

> I didn't really like the idea of hardcoding SDP records so I took different
> approach of doing reverse SDP search while cable associated device first
> connects. This is done before authorizing incoming HID connection.
>

I think ideally we should avoid making BlueZ aware of sixaxis in
input.c.

> Some functions unavailable to exteral plugins were renamed with btd_ prefix
> (or explicitly marked in bletooth.ver) to export them (patch 1-8).
>
> Patch 9-10 add sixaxis external plugin that depends on udev. This plugin is
> responsible for preparing newly USB connected PS3 sixaxis device and creating
> btd_device with proper PNP information.
>
> Patch 12 adds support for handling first connection of sixaxis device in input
> plugin itself. This is something I would like to get comments and suggestions.
> Currently this is rather sixaxis oriented, but could be made more generic (some
> hooks registration) if desired.
>
> This serie is not implemententing any LED (or other features) setting support.
> I have an impression that those should not be handled by BlueZ but some other
> entity (util tools or driver itself perhabs?) as this is not related to
> transport itself and should be set/used on USB connection as well.
>

Setting LEDs will need to be done by some code using udev anyway, as we
want the LED to match the X in the created /dev/input/jsX, so I thought
it may just go in the bluez plugin which is using udev already.

The kernel driver is at HID/input level in linux which is not aware of
the joystick layer, so it cannot know the joystick number, and
besides kernel driver should not be too smart anyway.

We cannot just count devices in the sixaxis kernel driver either,
consider this scenario:
- Connect a PS3 controller (js0, LED1)
- Connect some other joystick (js1)
- Connect another PS3 controller (js2, LED3)

> This was tested with Dualshock3 and seems to be working nicely here.
>
> Comments are welcome.
>

See above, but I don't think I am qualified to comment on your patches
12 and 13.

BTW considering that up to now I failed to have this merged I am not
going be picky, if BlueZ devs are happy with your approach, let's go
for it :)

Thanks,
Antonio

--
Antonio Ospite
http://ao2.it

A: Because it messes up the order in which people normally read text.
See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?

2013-11-25 22:15:52

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 13/13] input: Add support for handling sixaxis devices

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


2013-11-25 22:15:48

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 09/13] plugins: Add initial code for sixaxis plugin

This plugin will be used to associate PS3 controllers.
---
Makefile.plugins | 8 ++++++++
bootstrap-configure | 1 +
configure.ac | 5 +++++
plugins/sixaxis.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 60 insertions(+)
create mode 100644 plugins/sixaxis.c

diff --git a/Makefile.plugins b/Makefile.plugins
index 7c5f71d..f5025e9 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -110,3 +110,11 @@ builtin_sources += profiles/heartrate/heartrate.c
builtin_modules += cyclingspeed
builtin_sources += profiles/cyclingspeed/cyclingspeed.c
endif
+
+if SIXAXIS
+plugin_LTLIBRARIES += plugins/sixaxis.la
+plugins_sixaxis_la_SOURCES = plugins/sixaxis.c
+plugins_sixaxis_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \
+ -no-undefined @UDEV_LIBS@
+plugins_sixaxis_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden @UDEV_CFLAGS@
+endif
diff --git a/bootstrap-configure b/bootstrap-configure
index dc36311..c7f08ed 100755
--- a/bootstrap-configure
+++ b/bootstrap-configure
@@ -13,4 +13,5 @@ fi
--localstatedir=/var \
--enable-experimental \
--enable-android \
+ --enable-sixaxis \
--disable-datafiles $*
diff --git a/configure.ac b/configure.ac
index 949846e..ca226bb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -216,6 +216,11 @@ AC_ARG_ENABLE(experimental, AC_HELP_STRING([--enable-experimental],
[enable_experimental=${enableval}])
AM_CONDITIONAL(EXPERIMENTAL, test "${enable_experimental}" = "yes")

+AC_ARG_ENABLE(sixaxis, AC_HELP_STRING([--enable-sixaxis],
+ [enable sixaxis plugin]), [enable_sixaxis=${enableval}])
+AM_CONDITIONAL(SIXAXIS, test "${enable_sixaxis}" = "yes" &&
+ test "${enable_udev}" != "no")
+
if (test "${prefix}" = "NONE"); then
dnl no prefix and no localstatedir, so default to /var
if (test "$localstatedir" = '${prefix}/var'); then
diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
new file mode 100644
index 0000000..bf66bef
--- /dev/null
+++ b/plugins/sixaxis.c
@@ -0,0 +1,46 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2009 Bastien Nocera <[email protected]>
+ * Copyright (C) 2011 Antonio Ospite <[email protected]>
+ * Copyright (C) 2013 Szymon Janc <[email protected]>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "plugin.h"
+#include "log.h"
+
+static int sixaxis_init(void)
+{
+ DBG("");
+
+ return 0;
+}
+
+static void sixaxis_exit(void)
+{
+ DBG("");
+}
+
+BLUETOOTH_PLUGIN_DEFINE(sixaxis, VERSION, BLUETOOTH_PLUGIN_PRIORITY_LOW,
+ sixaxis_init, sixaxis_exit)
--
1.8.4.4


2013-11-25 22:15:51

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 12/13] device: Add device_discover_services function

This will allow to query remote services from plugins for not yet
discovered devices.
---
src/device.c | 17 +++++++++++++++++
src/device.h | 2 ++
2 files changed, 19 insertions(+)

diff --git a/src/device.c b/src/device.c
index 4e952c5..847ffad 100644
--- a/src/device.c
+++ b/src/device.c
@@ -3524,6 +3524,23 @@ static int device_browse_sdp(struct btd_device *device, DBusMessage *msg)
return err;
}

+int device_discover_services(struct btd_device *device)
+{
+ int err;
+
+ if (device_is_bredr(device))
+ err = device_browse_sdp(device, NULL);
+ else
+ err = device_browse_primary(device, NULL);
+
+ if (err == 0 && device->discov_timer) {
+ g_source_remove(device->discov_timer);
+ device->discov_timer = 0;
+ }
+
+ return err;
+}
+
struct btd_adapter *device_get_adapter(struct btd_device *device)
{
if (!device)
diff --git a/src/device.h b/src/device.h
index a0d25fe..c3fea4a 100644
--- a/src/device.h
+++ b/src/device.h
@@ -131,5 +131,7 @@ bool device_remove_svc_complete_callback(struct btd_device *dev,
struct btd_service *btd_device_get_service(struct btd_device *dev,
const char *remote_uuid);

+int device_discover_services(struct btd_device *device);
+
void btd_device_init(void);
void btd_device_cleanup(void);
--
1.8.4.4


2013-11-25 22:15:50

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 11/13] plugins/sixaxis: Add support for configuring new controllers

When new PS3 controller is detected provide it with default adapter
address. Also create new btd_device with proper PNP info if it wasn't
existing yet.
---
plugins/sixaxis.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 178 insertions(+), 1 deletion(-)

diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
index 7a5c6c2..86cfe82 100644
--- a/plugins/sixaxis.c
+++ b/plugins/sixaxis.c
@@ -29,19 +29,196 @@

#include <stddef.h>
#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <linux/hidraw.h>
+#include <linux/input.h>
#include <glib.h>
#include <libudev.h>

+#include "lib/bluetooth.h"
+#include "uuid.h"
+#include "adapter.h"
+#include "device.h"
#include "plugin.h"
#include "log.h"

+static const struct {
+ const char *name;
+ uint16_t source;
+ uint16_t vid;
+ uint16_t pid;
+ uint16_t version;
+} devices[] = {
+ {
+ .name = "PLAYSTATION(R)3 Controller",
+ .source = 0x0002,
+ .vid = 0x054c,
+ .pid = 0x0268,
+ .version = 0x0000,
+ },
+};
+
static struct udev *ctx = NULL;
static struct udev_monitor *monitor = NULL;
static guint watch_id = 0;

+static int get_device_bdaddr(int fd, bdaddr_t *bdaddr)
+{
+ uint8_t buf[18];
+ int ret;
+
+ memset(buf, 0, sizeof(buf));
+
+ buf[0] = 0xf2;
+
+ ret = ioctl(fd, HIDIOCGFEATURE(sizeof(buf)), buf);
+ if (ret < 0) {
+ error("sixaxis: failed to read device address (%s)",
+ strerror(errno));
+ return ret;
+ }
+
+ baswap(bdaddr, (bdaddr_t *) (buf + 4));
+
+ return 0;
+}
+
+static int get_master_bdaddr(int fd, bdaddr_t *bdaddr)
+{
+ uint8_t buf[8];
+ int ret;
+
+ memset(buf, 0, sizeof(buf));
+
+ buf[0] = 0xf5;
+
+ ret = ioctl(fd, HIDIOCGFEATURE(sizeof(buf)), buf);
+ if (ret < 0) {
+ error("sixaxis: failed to read master address (%s)",
+ strerror(errno));
+ return ret;
+ }
+
+ baswap(bdaddr, (bdaddr_t *) (buf + 2));
+
+ return 0;
+}
+
+static int set_master_bdaddr(int fd, const bdaddr_t *bdaddr)
+{
+ uint8_t buf[8];
+ int ret;
+
+ buf[0] = 0xf5;
+ buf[1] = 0x01;
+
+ baswap((bdaddr_t *) (buf + 2), bdaddr);
+
+ ret = ioctl(fd, HIDIOCSFEATURE(sizeof(buf)), buf);
+ if (ret < 0)
+ error("sixaxis: failed to write master address (%s)",
+ strerror(errno));
+
+ return ret;
+}
+
+static void setup_device(int fd, int index, struct btd_adapter *adapter)
+{
+ char device_addr[18], master_addr[18], adapter_addr[18];
+ bdaddr_t device_bdaddr, master_bdaddr;
+ const bdaddr_t *adapter_bdaddr;
+ struct btd_device *device;
+
+ if (get_device_bdaddr(fd, &device_bdaddr) < 0)
+ return;
+
+ if (get_master_bdaddr(fd, &master_bdaddr) < 0)
+ return;
+
+ adapter_bdaddr = btd_adapter_get_address(adapter);
+
+ if (bacmp(adapter_bdaddr, &master_bdaddr)) {
+ if (set_master_bdaddr(fd, adapter_bdaddr) < 0)
+ return;
+ }
+
+ ba2str(&device_bdaddr, device_addr);
+ ba2str(&master_bdaddr, master_addr);
+ ba2str(adapter_bdaddr, adapter_addr);
+ DBG("remote %s old_master %s new_master %s",
+ device_addr, master_addr, adapter_addr);
+
+ device = btd_adapter_get_device(adapter, &device_bdaddr, BDADDR_BREDR);
+
+ if (g_slist_find_custom(btd_device_get_uuids(device), HID_UUID,
+ (GCompareFunc)strcasecmp)) {
+ DBG("device %s already known, skipping", device_addr);
+ return;
+ }
+
+ info("sixaxis: setting up new device");
+
+ btd_device_device_set_name(device, devices[index].name);
+ btd_device_set_pnpid(device, devices[index].source, devices[index].vid,
+ devices[index].pid, devices[index].version);
+ btd_device_set_temporary(device, FALSE);
+ btd_device_set_trusted(device, TRUE);
+}
+
+static int get_supported_device(struct udev_device *udevice, uint16_t *bus)
+{
+ struct udev_device *hid_parent;
+ uint16_t vid, pid;
+ const char *hid_id;
+ int i;
+
+ hid_parent = udev_device_get_parent_with_subsystem_devtype(udevice,
+ "hid", NULL);
+ if (!hid_parent)
+ return -1;
+
+ hid_id = udev_device_get_property_value(hid_parent, "HID_ID");
+
+ if (sscanf(hid_id, "%hx:%hx:%hx", bus, &vid, &pid) != 3)
+ return -1;
+
+ for (i = 0; G_N_ELEMENTS(devices); i++) {
+ if (devices[i].vid == vid && devices[i].pid == pid)
+ return i;
+ }
+
+ return -1;
+}
+
static void device_added(struct udev_device *udevice)
{
- DBG("");
+ struct btd_adapter *adapter;
+ uint16_t bus;
+ int index;
+ int fd;
+
+ adapter = btd_adapter_get_default();
+ if (!adapter)
+ return;
+
+ index = get_supported_device(udevice, &bus);
+ if (index < 0)
+ return;
+
+ info("sixaxis: compatible device connected: %s (%04X:%04X)",
+ devices[index].name, devices[index].vid,
+ devices[index].pid);
+
+ fd = open(udev_device_get_devnode(udevice), O_RDWR);
+ if (fd < 0)
+ return;
+
+ if (bus == BUS_USB)
+ setup_device(fd, index, adapter);
+
+ close(fd);
}

static gboolean monitor_watch(GIOChannel *source, GIOCondition condition,
--
1.8.4.4


2013-11-25 22:15:45

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 06/13] Rename device_get_uuids to btd_device_get_uuids

Allow this symbol to be exported and usable from external plugins.
---
src/adapter.c | 2 +-
src/device.c | 2 +-
src/device.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 9600803..ec15715 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2537,7 +2537,7 @@ static void load_devices(struct btd_adapter *adapter)

/* TODO: register services from pre-loaded list of primaries */

- list = device_get_uuids(device);
+ list = btd_device_get_uuids(device);
if (list)
device_probe_profiles(device, list);

diff --git a/src/device.c b/src/device.c
index 58f24bf..4ff8a14 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2474,7 +2474,7 @@ static gboolean record_has_uuid(const sdp_record_t *rec,
return FALSE;
}

-GSList *device_get_uuids(struct btd_device *device)
+GSList *btd_device_get_uuids(struct btd_device *device)
{
return device->uuids;
}
diff --git a/src/device.h b/src/device.h
index 44bee3e..a0d25fe 100644
--- a/src/device.h
+++ b/src/device.h
@@ -46,7 +46,7 @@ uint16_t btd_device_get_version(struct btd_device *device);
void device_remove(struct btd_device *device, gboolean remove_stored);
int device_address_cmp(gconstpointer a, gconstpointer b);
int device_bdaddr_cmp(gconstpointer a, gconstpointer b);
-GSList *device_get_uuids(struct btd_device *device);
+GSList *btd_device_get_uuids(struct btd_device *device);
void device_probe_profiles(struct btd_device *device, GSList *profiles);
const sdp_record_t *btd_device_get_record(struct btd_device *device,
const char *uuid);
--
1.8.4.4


2013-11-25 22:15:47

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 08/13] Rename adapter_find_device to btd_adapter_find_device

Allow this symbol to be exported and usable from external plugins.
---
profiles/audio/avctp.c | 2 +-
profiles/audio/avdtp.c | 2 +-
profiles/input/device.c | 2 +-
src/adapter.c | 22 +++++++++++-----------
src/adapter.h | 2 +-
src/attrib-server.c | 2 +-
src/profile.c | 2 +-
7 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index 29fe763..4de981c 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -1371,7 +1371,7 @@ static void avctp_confirm_cb(GIOChannel *chan, gpointer data)

DBG("AVCTP: incoming connect from %s", address);

- device = adapter_find_device(adapter_find(&src), &dst);
+ device = btd_adapter_find_device(adapter_find(&src), &dst);
if (!device)
return;

diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index 9386c44..f866b39 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -2467,7 +2467,7 @@ static void avdtp_confirm_cb(GIOChannel *chan, gpointer data)

DBG("AVDTP: incoming connect from %s", address);

- device = adapter_find_device(adapter_find(&src), &dst);
+ device = btd_adapter_find_device(adapter_find(&src), &dst);
if (!device)
goto drop;

diff --git a/profiles/input/device.c b/profiles/input/device.c
index 71fe04a..0c2089b 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -880,7 +880,7 @@ static struct input_device *find_device(const bdaddr_t *src,
struct btd_device *device;
struct btd_service *service;

- device = adapter_find_device(adapter_find(src), dst);
+ device = btd_adapter_find_device(adapter_find(src), dst);
if (device == NULL)
return NULL;

diff --git a/src/adapter.c b/src/adapter.c
index a5a9ada..ea94753 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -690,7 +690,7 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
return set_name(adapter, name);
}

-struct btd_device *adapter_find_device(struct btd_adapter *adapter,
+struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter,
const bdaddr_t *dst)
{
struct btd_device *device;
@@ -1081,7 +1081,7 @@ struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter,
if (!adapter)
return NULL;

- device = adapter_find_device(adapter, addr);
+ device = btd_adapter_find_device(adapter, addr);
if (device)
return device;

@@ -4424,7 +4424,7 @@ static int adapter_authorize(struct btd_adapter *adapter, const bdaddr_t *dst,
struct btd_device *device;
static guint id = 0;

- device = adapter_find_device(adapter, dst);
+ device = btd_adapter_find_device(adapter, dst);
if (!device)
return 0;

@@ -4630,7 +4630,7 @@ int btd_adapter_pincode_reply(struct btd_adapter *adapter,

/* Since a pincode was requested, update the starting time to
* the point where the pincode is provided. */
- device = adapter_find_device(adapter, bdaddr);
+ device = btd_adapter_find_device(adapter, bdaddr);
device_bonding_restart_timer(device);

id = mgmt_reply(adapter->mgmt, MGMT_OP_PIN_CODE_REPLY,
@@ -4964,7 +4964,7 @@ static void bonding_complete(struct btd_adapter *adapter,
if (status == 0)
device = btd_adapter_get_device(adapter, bdaddr, addr_type);
else
- device = adapter_find_device(adapter, bdaddr);
+ device = btd_adapter_find_device(adapter, bdaddr);

if (device != NULL)
device_bonding_complete(device, status);
@@ -4991,7 +4991,7 @@ static void bonding_attempt_complete(struct btd_adapter *adapter,
if (status == 0)
device = btd_adapter_get_device(adapter, bdaddr, addr_type);
else
- device = adapter_find_device(adapter, bdaddr);
+ device = btd_adapter_find_device(adapter, bdaddr);

if (status == MGMT_STATUS_AUTH_FAILED && adapter->pincode_requested) {
/* On faliure, issue a bonding_retry if possible. */
@@ -5150,7 +5150,7 @@ static void dev_disconnected(struct btd_adapter *adapter,

DBG("Device %s disconnected, reason %u", dst, reason);

- device = adapter_find_device(adapter, &addr->bdaddr);
+ device = btd_adapter_find_device(adapter, &addr->bdaddr);
if (device)
adapter_remove_connection(adapter, device);

@@ -5765,7 +5765,7 @@ static void device_blocked_callback(uint16_t index, uint16_t length,
ba2str(&ev->addr.bdaddr, addr);
DBG("hci%u %s blocked", index, addr);

- device = adapter_find_device(adapter, &ev->addr.bdaddr);
+ device = btd_adapter_find_device(adapter, &ev->addr.bdaddr);
if (device)
device_block(device, TRUE);
}
@@ -5786,7 +5786,7 @@ static void device_unblocked_callback(uint16_t index, uint16_t length,
ba2str(&ev->addr.bdaddr, addr);
DBG("hci%u %s unblocked", index, addr);

- device = adapter_find_device(adapter, &ev->addr.bdaddr);
+ device = btd_adapter_find_device(adapter, &ev->addr.bdaddr);
if (device)
device_unblock(device, FALSE, TRUE);
}
@@ -5808,7 +5808,7 @@ static void connect_failed_callback(uint16_t index, uint16_t length,

DBG("hci%u %s status %u", index, addr, ev->status);

- device = adapter_find_device(adapter, &ev->addr.bdaddr);
+ device = btd_adapter_find_device(adapter, &ev->addr.bdaddr);
if (device) {
/* If the device is in a bonding process cancel any auth request
* sent to the agent before proceeding, but keep the bonding
@@ -5854,7 +5854,7 @@ static void unpaired_callback(uint16_t index, uint16_t length,

DBG("hci%u addr %s", index, addr);

- device = adapter_find_device(adapter, &ev->addr.bdaddr);
+ device = btd_adapter_find_device(adapter, &ev->addr.bdaddr);
if (!device) {
warn("No device object for unpaired device %s", addr);
return;
diff --git a/src/adapter.h b/src/adapter.h
index e982243..de5b07d 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -95,7 +95,7 @@ struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter,
uint8_t addr_type);
sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter);

-struct btd_device *adapter_find_device(struct btd_adapter *adapter,
+struct btd_device *btd_adapter_find_device(struct btd_adapter *adapter,
const bdaddr_t *dst);

const char *adapter_get_path(struct btd_adapter *adapter);
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 9231b5b..a6f1066 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -1137,7 +1137,7 @@ guint attrib_channel_attach(GAttrib *attrib)

channel->server = server;

- device = adapter_find_device(server->adapter, &channel->dst);
+ device = btd_adapter_find_device(server->adapter, &channel->dst);
if (device == NULL) {
error("Device object not found for attrib server");
g_free(channel);
diff --git a/src/profile.c b/src/profile.c
index 97cb1bc..3c0d27c 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -1047,7 +1047,7 @@ static struct ext_io *create_conn(struct ext_io *server, GIOChannel *io,
GIOCondition cond;
char addr[18];

- device = adapter_find_device(server->adapter, dst);
+ device = btd_adapter_find_device(server->adapter, dst);
if (device == NULL) {
ba2str(dst, addr);
error("%s device %s not found", server->ext->name, addr);
--
1.8.4.4


2013-11-25 22:15:46

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 07/13] Rename adapter_get_address to btd_adapter_get_address

Allow this symbol to be exported and usable from external plugins.
---
plugins/neard.c | 2 +-
plugins/wiimote.c | 2 +-
profiles/audio/avctp.c | 16 ++++++++++------
profiles/audio/avdtp.c | 9 ++++++---
profiles/health/hdp.c | 6 ++++--
profiles/health/hdp_util.c | 6 +++---
profiles/input/device.c | 2 +-
profiles/input/manager.c | 4 ++--
profiles/network/connection.c | 2 +-
profiles/network/server.c | 4 ++--
profiles/sap/server.c | 3 ++-
src/adapter.c | 6 +++---
src/adapter.h | 2 +-
src/attrib-server.c | 4 ++--
src/device.c | 31 ++++++++++++++++---------------
src/profile.c | 12 ++++++------
16 files changed, 61 insertions(+), 50 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index 58689e6..35fdaeb 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -227,7 +227,7 @@ static DBusMessage *create_request_oob_reply(struct btd_adapter *adapter,
uint8_t *peir = eir;
int len;

- len = eir_create_oob(adapter_get_address(adapter),
+ len = eir_create_oob(btd_adapter_get_address(adapter),
btd_adapter_get_name(adapter),
btd_adapter_get_class(adapter), hash,
randomizer, main_opts.did_vendor,
diff --git a/plugins/wiimote.c b/plugins/wiimote.c
index 6cc21ee..96a6569 100644
--- a/plugins/wiimote.c
+++ b/plugins/wiimote.c
@@ -106,7 +106,7 @@ static ssize_t wii_pincb(struct btd_adapter *adapter, struct btd_device *device,

found:
DBG("Forcing fixed pin on detected wiimote %s", addr);
- memcpy(pinbuf, adapter_get_address(adapter), 6);
+ memcpy(pinbuf, btd_adapter_get_address(adapter), 6);
return 6;
}

diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index 476f61a..29fe763 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -1307,7 +1307,7 @@ static void avctp_control_confirm(struct avctp *session, GIOChannel *chan,
avctp_set_state(session, AVCTP_STATE_CONNECTING);
session->control = avctp_channel_create(session, chan, NULL);

- src = adapter_get_address(device_get_adapter(dev));
+ src = btd_adapter_get_address(device_get_adapter(dev));
dst = device_get_address(dev);

session->auth_id = btd_request_authorization(src, dst,
@@ -1422,7 +1422,7 @@ static GIOChannel *avctp_server_socket(const bdaddr_t *src, gboolean master,
int avctp_register(struct btd_adapter *adapter, gboolean master)
{
struct avctp_server *server;
- const bdaddr_t *src = adapter_get_address(adapter);
+ const bdaddr_t *src = btd_adapter_get_address(adapter);

server = g_new0(struct avctp_server, 1);

@@ -1937,6 +1937,7 @@ struct avctp *avctp_connect(struct btd_device *device)
struct avctp *session;
GError *err = NULL;
GIOChannel *io;
+ const bdaddr_t *src;

session = avctp_get_internal(device);
if (!session)
@@ -1947,9 +1948,10 @@ struct avctp *avctp_connect(struct btd_device *device)

avctp_set_state(session, AVCTP_STATE_CONNECTING);

+ src = btd_adapter_get_address(session->server->adapter);
+
io = bt_io_connect(avctp_connect_cb, session, NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR,
- adapter_get_address(session->server->adapter),
+ BT_IO_OPT_SOURCE_BDADDR, src,
BT_IO_OPT_DEST_BDADDR,
device_get_address(session->device),
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
@@ -1971,6 +1973,7 @@ struct avctp *avctp_connect(struct btd_device *device)

int avctp_connect_browsing(struct avctp *session)
{
+ const bdaddr_t *src;
GError *err = NULL;
GIOChannel *io;

@@ -1982,9 +1985,10 @@ int avctp_connect_browsing(struct avctp *session)

avctp_set_state(session, AVCTP_STATE_BROWSING_CONNECTING);

+ src = btd_adapter_get_address(session->server->adapter);
+
io = bt_io_connect(avctp_connect_browsing_cb, session, NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR,
- adapter_get_address(session->server->adapter),
+ BT_IO_OPT_SOURCE_BDADDR, src,
BT_IO_OPT_DEST_BDADDR,
device_get_address(session->device),
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c
index b7a7d9c..9386c44 100644
--- a/profiles/audio/avdtp.c
+++ b/profiles/audio/avdtp.c
@@ -2523,11 +2523,13 @@ static GIOChannel *l2cap_connect(struct avdtp *session)
{
GError *err = NULL;
GIOChannel *io;
+ const bdaddr_t *src;
+
+ src = btd_adapter_get_address(session->server->adapter);

io = bt_io_connect(avdtp_connect_cb, session,
NULL, &err,
- BT_IO_OPT_SOURCE_BDADDR,
- adapter_get_address(session->server->adapter),
+ BT_IO_OPT_SOURCE_BDADDR, src,
BT_IO_OPT_DEST_BDADDR,
device_get_address(session->device),
BT_IO_OPT_PSM, AVDTP_PSM,
@@ -3675,7 +3677,8 @@ static struct avdtp_server *avdtp_server_init(struct btd_adapter *adapter)

server = g_new0(struct avdtp_server, 1);

- server->io = avdtp_server_socket(adapter_get_address(adapter), TRUE);
+ server->io = avdtp_server_socket(btd_adapter_get_address(adapter),
+ TRUE);
if (!server->io) {
g_free(server);
return NULL;
diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
index 86cebe6..6203fa8 100644
--- a/profiles/health/hdp.c
+++ b/profiles/health/hdp.c
@@ -1322,6 +1322,7 @@ static void release_adapter_instance(struct hdp_adapter *hdp_adapter)
static gboolean update_adapter(struct hdp_adapter *hdp_adapter)
{
GError *err = NULL;
+ const bdaddr_t *src;

if (applications == NULL) {
release_adapter_instance(hdp_adapter);
@@ -1331,8 +1332,9 @@ static gboolean update_adapter(struct hdp_adapter *hdp_adapter)
if (hdp_adapter->mi != NULL)
goto update;

- hdp_adapter->mi = mcap_create_instance(
- adapter_get_address(hdp_adapter->btd_adapter),
+ src = btd_adapter_get_address(hdp_adapter->btd_adapter);
+
+ hdp_adapter->mi = mcap_create_instance(src,
BT_IO_SEC_MEDIUM, 0, 0,
mcl_connected, mcl_reconnected,
mcl_disconnected, mcl_uncached,
diff --git a/profiles/health/hdp_util.c b/profiles/health/hdp_util.c
index 34e4671..7de87a8 100644
--- a/profiles/health/hdp_util.c
+++ b/profiles/health/hdp_util.c
@@ -853,7 +853,7 @@ gboolean hdp_get_mdep(struct hdp_device *device, struct hdp_application *app,
const bdaddr_t *dst;
uuid_t uuid;

- src = adapter_get_address(device_get_adapter(device->dev));
+ src = btd_adapter_get_address(device_get_adapter(device->dev));
dst = device_get_address(device->dev);

mdep_data = g_new0(struct get_mdep_data, 1);
@@ -1080,7 +1080,7 @@ gboolean hdp_establish_mcl(struct hdp_device *device,
const bdaddr_t *dst;
uuid_t uuid;

- src = adapter_get_address(device_get_adapter(device->dev));
+ src = btd_adapter_get_address(device_get_adapter(device->dev));
dst = device_get_address(device->dev);

conn_data = g_new0(struct conn_mcl_data, 1);
@@ -1151,7 +1151,7 @@ gboolean hdp_get_dcpsm(struct hdp_device *device, hdp_continue_dcpsm_f func,
const bdaddr_t *dst;
uuid_t uuid;

- src = adapter_get_address(device_get_adapter(device->dev));
+ src = btd_adapter_get_address(device_get_adapter(device->dev));
dst = device_get_address(device->dev);

dcpsm_data = g_new0(struct get_dcpsm_data, 1);
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 6523161..71fe04a 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -812,7 +812,7 @@ static struct input_device *input_device_new(struct btd_service *service)
char name[HCI_MAX_NAME_LENGTH + 1];

idev = g_new0(struct input_device, 1);
- bacpy(&idev->src, adapter_get_address(adapter));
+ bacpy(&idev->src, btd_adapter_get_address(adapter));
bacpy(&idev->dst, device_get_address(device));
idev->service = btd_service_ref(service);
idev->device = btd_device_ref(device);
diff --git a/profiles/input/manager.c b/profiles/input/manager.c
index 689ccdd..660043e 100644
--- a/profiles/input/manager.c
+++ b/profiles/input/manager.c
@@ -46,13 +46,13 @@

static int hid_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
{
- return server_start(adapter_get_address(adapter));
+ return server_start(btd_adapter_get_address(adapter));
}

static void hid_server_remove(struct btd_profile *p,
struct btd_adapter *adapter)
{
- server_stop(adapter_get_address(adapter));
+ server_stop(btd_adapter_get_address(adapter));
}

static struct btd_profile input_profile = {
diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 960a1fe..5966268 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -452,7 +452,7 @@ int connection_connect(struct btd_service *service)
if (nc->state != DISCONNECTED)
return -EALREADY;

- src = adapter_get_address(device_get_adapter(peer->device));
+ src = btd_adapter_get_address(device_get_adapter(peer->device));
dst = device_get_address(peer->device);

nc->io = bt_io_connect(connect_cb, nc,
diff --git a/profiles/network/server.c b/profiles/network/server.c
index 7b784e5..0050b30 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -765,7 +765,7 @@ static struct network_adapter *create_adapter(struct btd_adapter *adapter)
na->io = bt_io_listen(NULL, confirm_event, na,
NULL, &err,
BT_IO_OPT_SOURCE_BDADDR,
- adapter_get_address(adapter),
+ btd_adapter_get_address(adapter),
BT_IO_OPT_PSM, BNEP_PSM,
BT_IO_OPT_OMTU, BNEP_MTU,
BT_IO_OPT_IMTU, BNEP_MTU,
@@ -823,7 +823,7 @@ int server_register(struct btd_adapter *adapter, uint16_t id)
path);

done:
- bacpy(&ns->src, adapter_get_address(adapter));
+ bacpy(&ns->src, btd_adapter_get_address(adapter));
ns->id = id;
ns->na = na;
ns->record_id = 0;
diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index 63314a7..119862d 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -1372,7 +1372,8 @@ int sap_server_register(struct btd_adapter *adapter)

io = bt_io_listen(NULL, connect_confirm_cb, server,
NULL, &gerr,
- BT_IO_OPT_SOURCE_BDADDR, adapter_get_address(adapter),
+ BT_IO_OPT_SOURCE_BDADDR,
+ btd_adapter_get_address(adapter),
BT_IO_OPT_CHANNEL, SAP_SERVER_CHANNEL,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_HIGH,
BT_IO_OPT_MASTER, TRUE,
diff --git a/src/adapter.c b/src/adapter.c
index ec15715..a5a9ada 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3991,7 +3991,7 @@ const char *adapter_get_path(struct btd_adapter *adapter)
return adapter->path;
}

-const bdaddr_t *adapter_get_address(struct btd_adapter *adapter)
+const bdaddr_t *btd_adapter_get_address(struct btd_adapter *adapter)
{
return &adapter->bdaddr;
}
@@ -5225,7 +5225,7 @@ static void store_link_key(struct btd_adapter *adapter,
char *str;
int i;

- ba2str(adapter_get_address(adapter), adapter_addr);
+ ba2str(btd_adapter_get_address(adapter), adapter_addr);
ba2str(device_get_address(device), device_addr);

snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
@@ -5382,7 +5382,7 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length,

if (ev->store_hint) {
const struct mgmt_ltk_info *key = &ev->key;
- const bdaddr_t *bdaddr = adapter_get_address(adapter);
+ const bdaddr_t *bdaddr = btd_adapter_get_address(adapter);

store_longtermkey(bdaddr, &key->addr.bdaddr,
key->addr.type, key->val, key->master,
diff --git a/src/adapter.h b/src/adapter.h
index 8a2ddae..e982243 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -99,7 +99,7 @@ struct btd_device *adapter_find_device(struct btd_adapter *adapter,
const bdaddr_t *dst);

const char *adapter_get_path(struct btd_adapter *adapter);
-const bdaddr_t *adapter_get_address(struct btd_adapter *adapter);
+const bdaddr_t *btd_adapter_get_address(struct btd_adapter *adapter);
int adapter_set_name(struct btd_adapter *adapter, const char *name);

int adapter_service_add(struct btd_adapter *adapter, sdp_record_t *rec);
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 2861a00..9231b5b 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -156,7 +156,7 @@ static int adapter_cmp_addr(gconstpointer a, gconstpointer b)
const struct gatt_server *server = a;
const bdaddr_t *bdaddr = b;

- return bacmp(adapter_get_address(server->adapter), bdaddr);
+ return bacmp(btd_adapter_get_address(server->adapter), bdaddr);
}

static int adapter_cmp(gconstpointer a, gconstpointer b)
@@ -1310,7 +1310,7 @@ int btd_adapter_gatt_server_start(struct btd_adapter *adapter)
server = g_new0(struct gatt_server, 1);
server->adapter = btd_adapter_ref(adapter);

- addr = adapter_get_address(server->adapter);
+ addr = btd_adapter_get_address(server->adapter);

/* BR/EDR socket */
server->l2cap_io = bt_io_listen(connect_event, NULL, NULL, NULL, &gerr,
diff --git a/src/device.c b/src/device.c
index 4ff8a14..4e952c5 100644
--- a/src/device.c
+++ b/src/device.c
@@ -263,7 +263,7 @@ static gboolean store_device_info_cb(gpointer user_data)

device->store_id = 0;

- ba2str(adapter_get_address(device->adapter), adapter_addr);
+ ba2str(btd_adapter_get_address(device->adapter), adapter_addr);
ba2str(&device->bdaddr, device_addr);
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
device_addr);
@@ -409,7 +409,7 @@ void device_store_cached_name(struct btd_device *dev, const char *name)
return;
}

- ba2str(adapter_get_address(dev->adapter), s_addr);
+ ba2str(btd_adapter_get_address(dev->adapter), s_addr);
ba2str(&dev->bdaddr, d_addr);
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", s_addr, d_addr);
filename[PATH_MAX] = '\0';
@@ -470,7 +470,7 @@ static void browse_request_cancel(struct browse_req *req)
struct btd_device *device = req->device;
struct btd_adapter *adapter = device->adapter;

- bt_cancel_discovery(adapter_get_address(adapter), &device->bdaddr);
+ bt_cancel_discovery(btd_adapter_get_address(adapter), &device->bdaddr);

attio_cleanup(device);

@@ -2183,7 +2183,7 @@ struct btd_device *device_create_from_storage(struct btd_adapter *adapter,
if (device == NULL)
return NULL;

- src = adapter_get_address(adapter);
+ src = btd_adapter_get_address(adapter);
ba2str(src, srcaddr);

load_info(device, srcaddr, address, key_file);
@@ -2208,7 +2208,7 @@ struct btd_device *device_create(struct btd_adapter *adapter,
return NULL;

device->bdaddr_type = bdaddr_type;
- sba = adapter_get_address(adapter);
+ sba = btd_adapter_get_address(adapter);
ba2str(sba, src);

str = load_cached_name(device, src, dst);
@@ -2231,7 +2231,7 @@ char *btd_device_get_storage_path(struct btd_device *device,
return NULL;
}

- ba2str(adapter_get_address(device->adapter), srcaddr);
+ ba2str(btd_adapter_get_address(device->adapter), srcaddr);
ba2str(&device->bdaddr, dstaddr);

if (!filename)
@@ -2342,7 +2342,7 @@ static void delete_folder_tree(const char *dirname)

static void device_remove_stored(struct btd_device *device)
{
- const bdaddr_t *src = adapter_get_address(device->adapter);
+ const bdaddr_t *src = btd_adapter_get_address(device->adapter);
uint8_t dst_type = device->bdaddr_type;
char adapter_addr[18];
char device_addr[18];
@@ -2717,7 +2717,7 @@ static void update_bredr_services(struct browse_req *req, sdp_list_t *recs)
char *data;
gsize length = 0;

- ba2str(adapter_get_address(device->adapter), srcaddr);
+ ba2str(btd_adapter_get_address(device->adapter), srcaddr);
ba2str(&device->bdaddr, dstaddr);

if (!device->temporary) {
@@ -2961,7 +2961,7 @@ static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
/* Search for mandatory uuids */
if (uuid_list[req->search_uuid]) {
sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
- bt_search_service(adapter_get_address(adapter),
+ bt_search_service(btd_adapter_get_address(adapter),
&device->bdaddr, &uuid,
browse_cb, user_data, NULL);
return;
@@ -2994,7 +2994,7 @@ static void store_services(struct btd_device *device)
if (prim_uuid == NULL)
return;

- ba2str(adapter_get_address(adapter), src_addr);
+ ba2str(btd_adapter_get_address(adapter), src_addr);
ba2str(&device->bdaddr, dst_addr);

snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/attributes", src_addr,
@@ -3370,7 +3370,8 @@ int device_connect_le(struct btd_device *dev)
* pairing finishes
*/
io = bt_io_connect(att_connect_cb, attcb, NULL, &gerr,
- BT_IO_OPT_SOURCE_BDADDR, adapter_get_address(adapter),
+ BT_IO_OPT_SOURCE_BDADDR,
+ btd_adapter_get_address(adapter),
BT_IO_OPT_SOURCE_TYPE, BDADDR_LE_PUBLIC,
BT_IO_OPT_DEST_BDADDR, &dev->bdaddr,
BT_IO_OPT_DEST_TYPE, dev->bdaddr_type,
@@ -3453,7 +3454,7 @@ static int device_browse_primary(struct btd_device *device, DBusMessage *msg)
device->att_io = bt_io_connect(att_connect_cb,
attcb, NULL, NULL,
BT_IO_OPT_SOURCE_BDADDR,
- adapter_get_address(adapter),
+ btd_adapter_get_address(adapter),
BT_IO_OPT_SOURCE_TYPE, BDADDR_LE_PUBLIC,
BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
BT_IO_OPT_DEST_TYPE, device->bdaddr_type,
@@ -3499,8 +3500,8 @@ static int device_browse_sdp(struct btd_device *device, DBusMessage *msg)
req->device = device;
sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);

- err = bt_search_service(adapter_get_address(adapter), &device->bdaddr,
- &uuid, browse_cb, req, NULL);
+ err = bt_search_service(btd_adapter_get_address(adapter),
+ &device->bdaddr, &uuid, browse_cb, req, NULL);
if (err < 0) {
browse_request_free(req);
return err;
@@ -4280,7 +4281,7 @@ static sdp_list_t *read_device_records(struct btd_device *device)
sdp_list_t *recs = NULL;
sdp_record_t *rec;

- ba2str(adapter_get_address(device->adapter), local);
+ ba2str(btd_adapter_get_address(device->adapter), local);
ba2str(&device->bdaddr, peer);

snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer);
diff --git a/src/profile.c b/src/profile.c
index baadd99..97cb1bc 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -718,7 +718,7 @@ static void ext_io_destroy(gpointer p)
}

if (ext_io->resolving)
- bt_cancel_discovery(adapter_get_address(ext_io->adapter),
+ bt_cancel_discovery(btd_adapter_get_address(ext_io->adapter),
device_get_address(ext_io->device));

if (ext_io->adapter)
@@ -1257,7 +1257,7 @@ static uint32_t ext_start_servers(struct ext_profile *ext,

io = bt_io_listen(connect, confirm, l2cap, NULL, &err,
BT_IO_OPT_SOURCE_BDADDR,
- adapter_get_address(adapter),
+ btd_adapter_get_address(adapter),
BT_IO_OPT_MODE, ext->mode,
BT_IO_OPT_PSM, psm,
BT_IO_OPT_SEC_LEVEL, ext->sec_level,
@@ -1295,7 +1295,7 @@ static uint32_t ext_start_servers(struct ext_profile *ext,

io = bt_io_listen(connect, confirm, rfcomm, NULL, &err,
BT_IO_OPT_SOURCE_BDADDR,
- adapter_get_address(adapter),
+ btd_adapter_get_address(adapter),
BT_IO_OPT_CHANNEL, chan,
BT_IO_OPT_SEC_LEVEL, ext->sec_level,
BT_IO_OPT_INVALID);
@@ -1580,7 +1580,7 @@ static void record_cb(sdp_list_t *recs, int err, gpointer user_data)
goto failed;
}

- err = connect_io(conn, adapter_get_address(conn->adapter),
+ err = connect_io(conn, btd_adapter_get_address(conn->adapter),
device_get_address(conn->device));
if (err < 0) {
error("Connecting %s failed: %s", ext->name, strerror(-err));
@@ -1637,10 +1637,10 @@ static int ext_connect_dev(struct btd_service *service)
if (ext->remote_psm || ext->remote_chan) {
conn->psm = ext->remote_psm;
conn->chan = ext->remote_chan;
- err = connect_io(conn, adapter_get_address(adapter),
+ err = connect_io(conn, btd_adapter_get_address(adapter),
device_get_address(dev));
} else {
- err = resolve_service(conn, adapter_get_address(adapter),
+ err = resolve_service(conn, btd_adapter_get_address(adapter),
device_get_address(dev));
}

--
1.8.4.4


2013-11-25 22:15:49

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 10/13] plugins/sixaxis: Add initial code for udev handling

When new device is added plugin will be notified about it.
---
plugins/sixaxis.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)

diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
index bf66bef..7a5c6c2 100644
--- a/plugins/sixaxis.c
+++ b/plugins/sixaxis.c
@@ -27,19 +27,82 @@
#include <config.h>
#endif

+#include <stddef.h>
+#include <errno.h>
+#include <glib.h>
+#include <libudev.h>
+
#include "plugin.h"
#include "log.h"

+static struct udev *ctx = NULL;
+static struct udev_monitor *monitor = NULL;
+static guint watch_id = 0;
+
+static void device_added(struct udev_device *udevice)
+{
+ DBG("");
+}
+
+static gboolean monitor_watch(GIOChannel *source, GIOCondition condition,
+ gpointer data)
+{
+ struct udev_device *udevice;
+
+ udevice = udev_monitor_receive_device(monitor);
+ if (!udevice)
+ return TRUE;
+
+ if (!g_strcmp0(udev_device_get_action(udevice), "add"))
+ device_added(udevice);
+
+ udev_device_unref(udevice);
+
+ return TRUE;
+}
+
static int sixaxis_init(void)
{
+ GIOChannel *channel;
+
DBG("");

+ ctx = udev_new();
+ if (!ctx)
+ return -EIO;
+
+ monitor = udev_monitor_new_from_netlink(ctx, "udev");
+ if (!monitor) {
+ udev_unref(ctx);
+ ctx = NULL;
+
+ return -EIO;
+ }
+
+ /* Listen for newly connected hidraw interfaces */
+ udev_monitor_filter_add_match_subsystem_devtype(monitor, "hidraw",
+ NULL);
+ udev_monitor_enable_receiving(monitor);
+
+ channel = g_io_channel_unix_new(udev_monitor_get_fd(monitor));
+ watch_id = g_io_add_watch(channel, G_IO_IN, monitor_watch, NULL);
+ g_io_channel_unref(channel);
+
return 0;
}

static void sixaxis_exit(void)
{
DBG("");
+
+ g_source_remove(watch_id);
+ watch_id = 0;
+
+ udev_monitor_unref(monitor);
+ monitor = NULL;
+
+ udev_unref(ctx);
+ ctx = NULL;
}

BLUETOOTH_PLUGIN_DEFINE(sixaxis, VERSION, BLUETOOTH_PLUGIN_PRIORITY_LOW,
--
1.8.4.4


2013-11-25 22:15:44

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 05/13] Rename device_device_set_name to btd_device_device_set_name

Allow this symbol to be exported and usable from external plugins.
---
plugins/neard.c | 2 +-
src/adapter.c | 4 ++--
src/device.c | 2 +-
src/device.h | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index 073abec..58689e6 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -640,7 +640,7 @@ static void store_params(struct btd_adapter *adapter, struct btd_device *device,

if (params->name) {
device_store_cached_name(device, params->name);
- device_set_name(device, params->name);
+ btd_device_device_set_name(device, params->name);
}

/* TODO handle UUIDs? */
diff --git a/src/adapter.c b/src/adapter.c
index ccd3c43..9600803 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -4152,7 +4152,7 @@ static void update_found_devices(struct btd_adapter *adapter,
name_known = device_name_known(dev);

if (eir_data.name && (eir_data.name_complete || !name_known))
- device_set_name(dev, eir_data.name);
+ btd_device_device_set_name(dev, eir_data.name);

if (eir_data.class != 0)
device_set_class(dev, eir_data.class);
@@ -5743,7 +5743,7 @@ static void connected_callback(uint16_t index, uint16_t length,

if (eir_data.name != NULL) {
device_store_cached_name(device, eir_data.name);
- device_set_name(device, eir_data.name);
+ btd_device_device_set_name(device, eir_data.name);
}

eir_data_free(&eir_data);
diff --git a/src/device.c b/src/device.c
index e652329..58f24bf 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2241,7 +2241,7 @@ char *btd_device_get_storage_path(struct btd_device *device,
filename);
}

-void device_set_name(struct btd_device *device, const char *name)
+void btd_device_device_set_name(struct btd_device *device, const char *name)
{
if (strncmp(name, device->name, MAX_NAME_LENGTH) == 0)
return;
diff --git a/src/device.h b/src/device.h
index f7e7bdc..44bee3e 100644
--- a/src/device.h
+++ b/src/device.h
@@ -33,7 +33,7 @@ struct btd_device *device_create_from_storage(struct btd_adapter *adapter,
char *btd_device_get_storage_path(struct btd_device *device,
const char *filename);

-void device_set_name(struct btd_device *device, const char *name);
+void btd_device_device_set_name(struct btd_device *device, const char *name);
void device_store_cached_name(struct btd_device *dev, const char *name);
void device_get_name(struct btd_device *device, char *name, size_t len);
bool device_name_known(struct btd_device *device);
--
1.8.4.4


2013-11-25 22:15:41

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 02/13] Rename adapter_get_device to btd_adapter_get_device

Allow this symbol to be exported and usable from external plugins.
---
plugins/neard.c | 6 ++++--
profiles/health/hdp.c | 4 ++--
src/adapter.c | 28 +++++++++++++++++-----------
src/adapter.h | 2 +-
4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index ea91c4d..073abec 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -701,7 +701,8 @@ static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
return error_reply(msg, EINVAL);
}

- device = adapter_get_device(adapter, &remote.address, BDADDR_BREDR);
+ device = btd_adapter_get_device(adapter, &remote.address,
+ BDADDR_BREDR);

err = check_device(device);
if (err < 0) {
@@ -769,7 +770,8 @@ static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
if (bacmp(&remote.address, BDADDR_ANY) == 0)
goto read_local;

- device = adapter_get_device(adapter, &remote.address, BDADDR_BREDR);
+ device = btd_adapter_get_device(adapter, &remote.address,
+ BDADDR_BREDR);

err = check_device(device);
if (err < 0) {
diff --git a/profiles/health/hdp.c b/profiles/health/hdp.c
index 7b4e799..86cebe6 100644
--- a/profiles/health/hdp.c
+++ b/profiles/health/hdp.c
@@ -1205,8 +1205,8 @@ static void mcl_connected(struct mcap_mcl *mcl, gpointer data)
struct hdp_adapter *hdp_adapter = data;
struct btd_device *device;

- device = adapter_get_device(hdp_adapter->btd_adapter, &addr,
- BDADDR_BREDR);
+ device = btd_adapter_get_device(hdp_adapter->btd_adapter,
+ &addr, BDADDR_BREDR);
if (!device)
return;
hdp_device = create_health_device(device);
diff --git a/src/adapter.c b/src/adapter.c
index d904a56..8a6dadf 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1072,7 +1072,7 @@ static void adapter_remove_device(struct btd_adapter *adapter,
device_remove(dev, TRUE);
}

-struct btd_device *adapter_get_device(struct btd_adapter *adapter,
+struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter,
const bdaddr_t *addr,
uint8_t addr_type)
{
@@ -2726,7 +2726,8 @@ static void get_connections_complete(uint8_t status, uint16_t length,
ba2str(&addr->bdaddr, address);
DBG("Adding existing connection to %s", address);

- device = adapter_get_device(adapter, &addr->bdaddr, addr->type);
+ device = btd_adapter_get_device(adapter, &addr->bdaddr,
+ addr->type);
if (device)
adapter_add_connection(adapter, device);
}
@@ -4687,7 +4688,8 @@ static void user_confirm_request_callback(uint16_t index, uint16_t length,
ba2str(&ev->addr.bdaddr, addr);
DBG("hci%u %s confirm_hint %u", adapter->dev_id, addr,
ev->confirm_hint);
- device = adapter_get_device(adapter, &ev->addr.bdaddr, ev->addr.type);
+ device = btd_adapter_get_device(adapter, &ev->addr.bdaddr,
+ ev->addr.type);
if (!device) {
error("Unable to get device object for %s", addr);
return;
@@ -4758,7 +4760,8 @@ static void user_passkey_request_callback(uint16_t index, uint16_t length,
ba2str(&ev->addr.bdaddr, addr);
DBG("hci%u %s", index, addr);

- device = adapter_get_device(adapter, &ev->addr.bdaddr, ev->addr.type);
+ device = btd_adapter_get_device(adapter, &ev->addr.bdaddr,
+ ev->addr.type);
if (!device) {
error("Unable to get device object for %s", addr);
return;
@@ -4790,7 +4793,8 @@ static void user_passkey_notify_callback(uint16_t index, uint16_t length,
ba2str(&ev->addr.bdaddr, addr);
DBG("hci%u %s", index, addr);

- device = adapter_get_device(adapter, &ev->addr.bdaddr, ev->addr.type);
+ device = btd_adapter_get_device(adapter, &ev->addr.bdaddr,
+ ev->addr.type);
if (!device) {
error("Unable to get device object for %s", addr);
return;
@@ -4872,7 +4876,8 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,

DBG("hci%u %s", adapter->dev_id, addr);

- device = adapter_get_device(adapter, &ev->addr.bdaddr, ev->addr.type);
+ device = btd_adapter_get_device(adapter, &ev->addr.bdaddr,
+ ev->addr.type);
if (!device) {
error("Unable to get device object for %s", addr);
return;
@@ -4957,7 +4962,7 @@ static void bonding_complete(struct btd_adapter *adapter,
struct btd_device *device;

if (status == 0)
- device = adapter_get_device(adapter, bdaddr, addr_type);
+ device = btd_adapter_get_device(adapter, bdaddr, addr_type);
else
device = adapter_find_device(adapter, bdaddr);

@@ -4984,7 +4989,7 @@ static void bonding_attempt_complete(struct btd_adapter *adapter,
addr_type, status);

if (status == 0)
- device = adapter_get_device(adapter, bdaddr, addr_type);
+ device = btd_adapter_get_device(adapter, bdaddr, addr_type);
else
device = adapter_find_device(adapter, bdaddr);

@@ -5274,7 +5279,7 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
return;
}

- device = adapter_get_device(adapter, &addr->bdaddr, addr->type);
+ device = btd_adapter_get_device(adapter, &addr->bdaddr, addr->type);
if (!device) {
error("Unable to get device object for %s", dst);
return;
@@ -5369,7 +5374,7 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length,
DBG("hci%u new LTK for %s authenticated %u enc_size %u",
adapter->dev_id, dst, ev->key.authenticated, ev->key.enc_size);

- device = adapter_get_device(adapter, &addr->bdaddr, addr->type);
+ device = btd_adapter_get_device(adapter, &addr->bdaddr, addr->type);
if (!device) {
error("Unable to get device object for %s", dst);
return;
@@ -5720,7 +5725,8 @@ static void connected_callback(uint16_t index, uint16_t length,

DBG("hci%u device %s connected eir_len %u", index, addr, eir_len);

- device = adapter_get_device(adapter, &ev->addr.bdaddr, ev->addr.type);
+ device = btd_adapter_get_device(adapter, &ev->addr.bdaddr,
+ ev->addr.type);
if (!device) {
error("Unable to get device object for %s", addr);
return;
diff --git a/src/adapter.h b/src/adapter.h
index 80c5f77..8a2ddae 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -90,7 +90,7 @@ bool btd_adapter_get_connectable(struct btd_adapter *adapter);

uint32_t btd_adapter_get_class(struct btd_adapter *adapter);
const char *btd_adapter_get_name(struct btd_adapter *adapter);
-struct btd_device *adapter_get_device(struct btd_adapter *adapter,
+struct btd_device *btd_adapter_get_device(struct btd_adapter *adapter,
const bdaddr_t *addr,
uint8_t addr_type);
sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter);
--
1.8.4.4


2013-11-25 22:15:43

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 04/13] Rename device_set_trusted to btd_device_set_trusted

Allow this symbol to be exported and usable from external plugins.
---
src/device.c | 4 ++--
src/device.h | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/device.c b/src/device.c
index 59e65b9..e652329 100644
--- a/src/device.c
+++ b/src/device.c
@@ -809,7 +809,7 @@ static void set_trust(GDBusPendingPropertySet id, gboolean value, void *data)
{
struct btd_device *device = data;

- device_set_trusted(device, value);
+ btd_device_set_trusted(device, value);

g_dbus_pending_property_success(id);
}
@@ -3565,7 +3565,7 @@ void btd_device_set_temporary(struct btd_device *device, gboolean temporary)
device->temporary = temporary;
}

-void device_set_trusted(struct btd_device *device, gboolean trusted)
+void btd_device_set_trusted(struct btd_device *device, gboolean trusted)
{
if (!device)
return;
diff --git a/src/device.h b/src/device.h
index 35d2a75..f7e7bdc 100644
--- a/src/device.h
+++ b/src/device.h
@@ -70,7 +70,7 @@ gboolean device_is_bonded(struct btd_device *device);
gboolean device_is_trusted(struct btd_device *device);
void device_set_paired(struct btd_device *device, gboolean paired);
void btd_device_set_temporary(struct btd_device *device, gboolean temporary);
-void device_set_trusted(struct btd_device *device, gboolean trusted);
+void btd_device_set_trusted(struct btd_device *device, gboolean trusted);
void device_set_bonded(struct btd_device *device, gboolean bonded);
void device_set_legacy(struct btd_device *device, bool legacy);
void device_set_rssi(struct btd_device *device, int8_t rssi);
--
1.8.4.4


2013-11-25 22:15:42

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 03/13] Rename device_set_temporary to btd_device_set_temporary

Allow this symbol to be exported and usable from external plugins.
---
src/adapter.c | 12 ++++++------
src/device.c | 14 +++++++-------
src/device.h | 2 +-
3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 8a6dadf..ccd3c43 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1012,7 +1012,7 @@ static struct btd_device *adapter_create_device(struct btd_adapter *adapter,
if (!device)
return NULL;

- device_set_temporary(device, TRUE);
+ btd_device_set_temporary(device, TRUE);

adapter->devices = g_slist_append(adapter->devices, device);

@@ -2156,7 +2156,7 @@ static DBusMessage *remove_device(DBusConnection *conn,

device = list->data;

- device_set_temporary(device, TRUE);
+ btd_device_set_temporary(device, TRUE);

if (!device_is_connected(device)) {
adapter_remove_device(adapter, device);
@@ -2532,7 +2532,7 @@ static void load_devices(struct btd_adapter *adapter)
if (!device)
goto free;

- device_set_temporary(device, FALSE);
+ btd_device_set_temporary(device, FALSE);
adapter->devices = g_slist_append(adapter->devices, device);

/* TODO: register services from pre-loaded list of primaries */
@@ -5294,7 +5294,7 @@ static void new_link_key_callback(uint16_t index, uint16_t length,
device_set_bonded(device, TRUE);

if (device_is_temporary(device))
- device_set_temporary(device, FALSE);
+ btd_device_set_temporary(device, FALSE);
}

bonding_complete(adapter, &addr->bdaddr, addr->type, 0);
@@ -5392,7 +5392,7 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length,
device_set_bonded(device, TRUE);

if (device_is_temporary(device))
- device_set_temporary(device, FALSE);
+ btd_device_set_temporary(device, FALSE);
}

if (ev->key.master)
@@ -5860,7 +5860,7 @@ static void unpaired_callback(uint16_t index, uint16_t length,
return;
}

- device_set_temporary(device, TRUE);
+ btd_device_set_temporary(device, TRUE);

if (device_is_connected(device))
device_request_disconnect(device, NULL);
diff --git a/src/device.c b/src/device.c
index c0e317d..59e65b9 100644
--- a/src/device.c
+++ b/src/device.c
@@ -997,7 +997,7 @@ int device_block(struct btd_device *device, gboolean update_only)

store_device_info(device);

- device_set_temporary(device, FALSE);
+ btd_device_set_temporary(device, FALSE);

g_dbus_emit_property_changed(dbus_conn, device->path,
DEVICE_INTERFACE, "Blocked");
@@ -1152,7 +1152,7 @@ static void device_profile_connected(struct btd_device *dev,
DBG("%s %s (%d)", profile->name, strerror(-err), -err);

if (!err)
- device_set_temporary(dev, FALSE);
+ btd_device_set_temporary(dev, FALSE);

if (dev->pending == NULL)
return;
@@ -1308,7 +1308,7 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg,
if (!btd_adapter_get_powered(dev->adapter))
return btd_error_not_ready(msg);

- device_set_temporary(dev, FALSE);
+ btd_device_set_temporary(dev, FALSE);

if (!dev->svc_resolved)
goto resolve_services;
@@ -1358,7 +1358,7 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,
if (device_is_connected(dev))
return dbus_message_new_method_return(msg);

- device_set_temporary(dev, FALSE);
+ btd_device_set_temporary(dev, FALSE);

dev->disable_auto_connect = FALSE;

@@ -1609,7 +1609,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
uint8_t io_cap;
int err;

- device_set_temporary(device, FALSE);
+ btd_device_set_temporary(device, FALSE);

if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID))
return btd_error_invalid_args(msg);
@@ -3112,7 +3112,7 @@ static void register_all_services(struct browse_req *req, GSList *services)
{
struct btd_device *device = req->device;

- device_set_temporary(device, FALSE);
+ btd_device_set_temporary(device, FALSE);

update_gatt_services(req, device->primaries, services);
g_slist_free_full(device->primaries, g_free);
@@ -3549,7 +3549,7 @@ gboolean device_is_temporary(struct btd_device *device)
return device->temporary;
}

-void device_set_temporary(struct btd_device *device, gboolean temporary)
+void btd_device_set_temporary(struct btd_device *device, gboolean temporary)
{
if (!device)
return;
diff --git a/src/device.h b/src/device.h
index deec8d0..35d2a75 100644
--- a/src/device.h
+++ b/src/device.h
@@ -69,7 +69,7 @@ gboolean device_is_paired(struct btd_device *device);
gboolean device_is_bonded(struct btd_device *device);
gboolean device_is_trusted(struct btd_device *device);
void device_set_paired(struct btd_device *device, gboolean paired);
-void device_set_temporary(struct btd_device *device, gboolean temporary);
+void btd_device_set_temporary(struct btd_device *device, gboolean temporary);
void device_set_trusted(struct btd_device *device, gboolean trusted);
void device_set_bonded(struct btd_device *device, gboolean bonded);
void device_set_legacy(struct btd_device *device, bool legacy);
--
1.8.4.4


2013-11-25 22:15:40

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 01/13] core: Export some symbols from libbluetooth

Those are commonly used and should be available for external plugins.
---
src/bluetooth.ver | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src/bluetooth.ver b/src/bluetooth.ver
index b71c70d..214fa8a 100644
--- a/src/bluetooth.ver
+++ b/src/bluetooth.ver
@@ -5,6 +5,8 @@
info;
error;
debug;
+ baswap;
+ ba2str;
local:
*;
};
--
1.8.4.4