From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Cc: Bastien Nocera <hadess@hadess.net>
Subject: [PATCH 7/9] plugins/sixaxis: Rename sixaxis specific functions
Date: Mon, 4 Sep 2017 20:12:10 +0200 [thread overview]
Message-ID: <20170904181212.5639-7-hadess@hadess.net> (raw)
In-Reply-To: <20170904181212.5639-1-hadess@hadess.net>
And provide wrappers to prepare for the addition of other device types.
---
plugins/sixaxis.c | 39 ++++++++++++++++++++++++++++++++-------
1 file changed, 32 insertions(+), 7 deletions(-)
diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
index 3e8ac06ca..b62834d72 100644
--- a/plugins/sixaxis.c
+++ b/plugins/sixaxis.c
@@ -55,13 +55,14 @@ struct authentication_closure {
struct btd_device *device;
int fd;
char device_addr[18];
+ CablePairingType type;
};
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)
+static int sixaxis_get_device_bdaddr(int fd, bdaddr_t *bdaddr)
{
uint8_t buf[18];
int ret;
@@ -82,7 +83,14 @@ static int get_device_bdaddr(int fd, bdaddr_t *bdaddr)
return 0;
}
-static int get_master_bdaddr(int fd, bdaddr_t *bdaddr)
+static int get_device_bdaddr(int fd, bdaddr_t *bdaddr, CablePairingType type)
+{
+ if (type == CABLE_PAIRING_SIXAXIS)
+ return sixaxis_get_device_bdaddr(fd, bdaddr);
+ return -1;
+}
+
+static int sixaxis_get_master_bdaddr(int fd, bdaddr_t *bdaddr)
{
uint8_t buf[8];
int ret;
@@ -103,7 +111,14 @@ static int get_master_bdaddr(int fd, bdaddr_t *bdaddr)
return 0;
}
-static int set_master_bdaddr(int fd, const bdaddr_t *bdaddr)
+static int get_master_bdaddr(int fd, bdaddr_t *bdaddr, CablePairingType type)
+{
+ if (type == CABLE_PAIRING_SIXAXIS)
+ return sixaxis_get_master_bdaddr(fd, bdaddr);
+ return -1;
+}
+
+static int sixaxis_set_master_bdaddr(int fd, const bdaddr_t *bdaddr)
{
uint8_t buf[8];
int ret;
@@ -121,6 +136,14 @@ static int set_master_bdaddr(int fd, const bdaddr_t *bdaddr)
return ret;
}
+static int set_master_bdaddr(int fd, const bdaddr_t *bdaddr,
+ CablePairingType type)
+{
+ if (type == CABLE_PAIRING_SIXAXIS)
+ return sixaxis_set_master_bdaddr(fd, bdaddr);
+ return -1;
+}
+
static void agent_auth_cb(DBusError *derr,
void *user_data)
{
@@ -136,12 +159,12 @@ static void agent_auth_cb(DBusError *derr,
btd_device_set_temporary(closure->device, false);
- if (get_master_bdaddr(closure->fd, &master_bdaddr) < 0)
+ if (get_master_bdaddr(closure->fd, &master_bdaddr, closure->type) < 0)
goto error;
adapter_bdaddr = btd_adapter_get_address(closure->adapter);
if (bacmp(adapter_bdaddr, &master_bdaddr)) {
- if (set_master_bdaddr(closure->fd, adapter_bdaddr) < 0)
+ if (set_master_bdaddr(closure->fd, adapter_bdaddr, closure->type) < 0)
goto error;
}
@@ -161,6 +184,7 @@ static bool setup_device(int fd,
uint16_t vid,
uint16_t pid,
uint16_t version,
+ CablePairingType type,
struct btd_adapter *adapter)
{
char device_addr[18];
@@ -169,7 +193,7 @@ static bool setup_device(int fd,
struct btd_device *device;
struct authentication_closure *closure;
- if (get_device_bdaddr(fd, &device_bdaddr) < 0)
+ if (get_device_bdaddr(fd, &device_bdaddr, type) < 0)
return false;
/* This can happen if controller was plugged while already connected
@@ -203,6 +227,7 @@ static bool setup_device(int fd,
closure->adapter = adapter;
closure->device = device;
closure->fd = fd;
+ closure->type = type;
memcpy(&closure->device_addr, device_addr, sizeof(device_addr));
adapter_bdaddr = btd_adapter_get_address(adapter);
btd_request_authorization_cable_configured(adapter_bdaddr, &device_bdaddr,
@@ -269,7 +294,7 @@ static void device_added(struct udev_device *udevice)
}
/* Only close the fd if an authentication is not pending */
- if (!setup_device(fd, name, source, vid, pid, version, adapter))
+ if (!setup_device(fd, name, source, vid, pid, version, type, adapter))
close(fd);
g_free(name);
--
2.14.1
next prev parent reply other threads:[~2017-09-04 18:12 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-04 18:12 [PATCH 1/9] plugins/sixaxis: Remove LEDs handling Bastien Nocera
2017-09-04 18:12 ` [PATCH 2/9] adapter: Add btd_request_authorization_cable_configured() Bastien Nocera
2017-09-04 18:12 ` [PATCH 3/9] sixaxis: Ask user whether cable configuration should be allowed Bastien Nocera
2017-09-27 9:12 ` Szymon Janc
2017-10-18 1:51 ` Bastien Nocera
2017-09-27 9:14 ` Szymon Janc
2017-10-04 12:38 ` Bastien Nocera
2017-09-04 18:12 ` [PATCH 4/9] plugins/sixaxis: Move device discovery to shared header Bastien Nocera
2017-09-05 9:03 ` Bastien Nocera
2017-09-05 9:13 ` Szymon Janc
2017-09-05 10:37 ` Bastien Nocera
2017-09-04 18:12 ` [PATCH 5/9] profiles/input: Use sixaxis header to simplify device detection Bastien Nocera
2017-09-04 18:12 ` [PATCH 6/9] profiles/input: Add DS4 devices to the shared header Bastien Nocera
2017-09-04 18:12 ` Bastien Nocera [this message]
2017-09-04 18:12 ` [PATCH 8/9] plugins/sixaxis: Add support for DualShock 4/PS4 cable pairing Bastien Nocera
2017-09-27 9:12 ` Szymon Janc
2017-10-04 12:40 ` Bastien Nocera
2017-10-18 1:51 ` Bastien Nocera
2017-09-04 18:12 ` [PATCH 9/9] plugins/sixaxis: Cancel cable pairing if unplugged Bastien Nocera
2017-09-27 9:07 ` [PATCH 1/9] plugins/sixaxis: Remove LEDs handling 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=20170904181212.5639-7-hadess@hadess.net \
--to=hadess@hadess.net \
--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).