2012-04-05 22:29:32

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 0/8] Support for displaying PIN for entry into device

Rationale: The Bluetooth HID specification recommends that keyboards be
paired by generating a PIN on the host and displaying it for entry into
the pairing keyboard. This is also the case for other kinds of devices,
for example the GNOME Bluetooth wizard does something similar for the
CMT-DH5BT audio device.

Current deployments, such as GNOME Bluetooth and Android, perform this
generation inside the Agent which means each has to implement their
own code to do the same thing. The intent of this patch is to move this
common behavior into BlueZ so all can benefit.

My previous patch set performed this generation inside bluetoothd
itself, this new version assumes that a plugin will do it and simply
provides the mechanism for doing so.

I've also dropped the bt_ids header from the set.

Scott James Remnant (8):
Rename AUTH_TYPE_NOTIFY to AUTH_TYPE_NOTIFY_PASSKEY
Pass passkey by pointer rather than by value
agent: add DisplayPinCode method
Add AUTH_TYPE_NOTIFY_PASSKEY to device_request_authentication
Add display parameter to plugin pincode callback
Display PIN generated by plugin
doc: document DisplayPinCode
simple-agent: add DisplayPinCode

doc/agent-api.txt | 24 +++++++++++
plugins/wiimote.c | 2 +-
src/adapter.c | 4 +-
src/adapter.h | 4 +-
src/agent.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/agent.h | 4 ++
src/device.c | 72 ++++++++++++++++++++++++++++++----
src/device.h | 5 +-
src/event.c | 18 ++++++---
test/simple-agent | 5 ++
10 files changed, 228 insertions(+), 22 deletions(-)

--
1.7.7.3



2012-04-12 11:13:41

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv3 0/8] Support for displaying PIN for entry into device

Hi Scott,

On Thu, Apr 05, 2012, Scott James Remnant wrote:
> Rationale: The Bluetooth HID specification recommends that keyboards be
> paired by generating a PIN on the host and displaying it for entry into
> the pairing keyboard. This is also the case for other kinds of devices,
> for example the GNOME Bluetooth wizard does something similar for the
> CMT-DH5BT audio device.
>
> Current deployments, such as GNOME Bluetooth and Android, perform this
> generation inside the Agent which means each has to implement their
> own code to do the same thing. The intent of this patch is to move this
> common behavior into BlueZ so all can benefit.
>
> My previous patch set performed this generation inside bluetoothd
> itself, this new version assumes that a plugin will do it and simply
> provides the mechanism for doing so.
>
> I've also dropped the bt_ids header from the set.
>
> Scott James Remnant (8):
> Rename AUTH_TYPE_NOTIFY to AUTH_TYPE_NOTIFY_PASSKEY
> Pass passkey by pointer rather than by value
> agent: add DisplayPinCode method
> Add AUTH_TYPE_NOTIFY_PASSKEY to device_request_authentication
> Add display parameter to plugin pincode callback
> Display PIN generated by plugin
> doc: document DisplayPinCode
> simple-agent: add DisplayPinCode
>
> doc/agent-api.txt | 24 +++++++++++
> plugins/wiimote.c | 2 +-
> src/adapter.c | 4 +-
> src/adapter.h | 4 +-
> src/agent.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
> src/agent.h | 4 ++
> src/device.c | 72 ++++++++++++++++++++++++++++++----
> src/device.h | 5 +-
> src/event.c | 18 ++++++---
> test/simple-agent | 5 ++
> 10 files changed, 228 insertions(+), 22 deletions(-)

All patches in this set have been applied upstream. There were a few
coding style issues I fixed myself while applying (incorrect tabbing for
line splits and missing spaces in type casts) but other than that I
didn't find anything to object to. Thanks.

Johan

2012-04-05 22:29:40

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 8/8] simple-agent: add DisplayPinCode

---
test/simple-agent | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/test/simple-agent b/test/simple-agent
index af84815..38d0235 100755
--- a/test/simple-agent
+++ b/test/simple-agent
@@ -52,6 +52,11 @@ class Agent(dbus.service.Object):
print "DisplayPasskey (%s, %06d)" % (device, passkey)

@dbus.service.method("org.bluez.Agent",
+ in_signature="os", out_signature="")
+ def DisplayPinCode(self, device, pincode):
+ print "DisplayPinCode (%s, %s)" % (device, pincode)
+
+ @dbus.service.method("org.bluez.Agent",
in_signature="ou", out_signature="")
def RequestConfirmation(self, device, passkey):
print "RequestConfirmation (%s, %06d)" % (device, passkey)
--
1.7.7.3


2012-04-05 22:29:39

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 7/8] doc: document DisplayPinCode

---
doc/agent-api.txt | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/doc/agent-api.txt b/doc/agent-api.txt
index 9ab2063..5c8d4d2 100644
--- a/doc/agent-api.txt
+++ b/doc/agent-api.txt
@@ -61,6 +61,30 @@ Methods void Release()
so the display should be zero-padded at the start if
the value contains less than 6 digits.

+ void DisplayPinCode(object device, string pincode)
+
+ This method gets called when the service daemon
+ needs to display a pincode for an authentication.
+
+ An empty reply should be returned. When the pincode
+ needs no longer to be displayed, the Cancel method
+ of the agent will be called.
+
+ If this method is not implemented the RequestPinCode
+ method will be used instead.
+
+ This is used during the pairing process of keyboards
+ that don't support Bluetooth 2.1 Secure Simple Pairing,
+ in contrast to DisplayPasskey which is used for those
+ that do.
+
+ This method will only ever be called once since
+ older keyboards do not support typing notification.
+
+ Note that the PIN will always be a 6-digit number,
+ zero-padded to 6 digits. This is for harmony with
+ the later specification.
+
void RequestConfirmation(object device, uint32 passkey)

This method gets called when the service daemon
--
1.7.7.3


2012-04-05 22:29:38

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 6/8] Display PIN generated by plugin

If a plugin pincode callback sets the display parameter to TRUE, send
the generated PIN to the agent for display using the new DisplayPinCode
agent method, including its fallback to RequestPinCode.
---
src/event.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/event.c b/src/event.c
index b37f411..876bd37 100644
--- a/src/event.c
+++ b/src/event.c
@@ -127,6 +127,11 @@ int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba, gboolean secure)
memset(pin, 0, sizeof(pin));
pinlen = btd_adapter_get_pin(adapter, device, pin, &display);
if (pinlen > 0 && (!secure || pinlen == 16)) {
+ if (display && device_is_bonding(device, NULL))
+ return device_request_authentication(device,
+ AUTH_TYPE_NOTIFY_PINCODE, pin,
+ secure, pincode_cb);
+
btd_adapter_pincode_reply(adapter, dba, pin, pinlen);
return 0;
}
--
1.7.7.3


2012-04-05 22:29:37

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 5/8] Add display parameter to plugin pincode callback

Pass a display parameter to the plugin pincode callback, a plugin
may set this to TRUE to indicate the PIN it generates should be
displayed on the screen for entry into the remote device.
---
plugins/wiimote.c | 2 +-
src/adapter.c | 4 ++--
src/adapter.h | 4 ++--
src/event.c | 3 ++-
4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/plugins/wiimote.c b/plugins/wiimote.c
index 568bfd5..9c69c6d 100644
--- a/plugins/wiimote.c
+++ b/plugins/wiimote.c
@@ -57,7 +57,7 @@
*/

static ssize_t wii_pincb(struct btd_adapter *adapter, struct btd_device *device,
- char *pinbuf)
+ char *pinbuf, gboolean *display)
{
uint16_t vendor, product;
bdaddr_t sba, dba;
diff --git a/src/adapter.c b/src/adapter.c
index d5c1a04..d10db10 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3345,7 +3345,7 @@ void btd_adapter_unregister_pin_cb(struct btd_adapter *adapter,
}

ssize_t btd_adapter_get_pin(struct btd_adapter *adapter, struct btd_device *dev,
- char *pin_buf)
+ char *pin_buf, gboolean *display)
{
GSList *l;
btd_adapter_pin_cb_t cb;
@@ -3354,7 +3354,7 @@ ssize_t btd_adapter_get_pin(struct btd_adapter *adapter, struct btd_device *dev,

for (l = adapter->pin_callbacks; l != NULL; l = g_slist_next(l)) {
cb = l->data;
- ret = cb(adapter, dev, pin_buf);
+ ret = cb(adapter, dev, pin_buf, display);
if (ret > 0)
return ret;
}
diff --git a/src/adapter.h b/src/adapter.h
index c47d180..196713e 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -172,13 +172,13 @@ int btd_adapter_switch_offline(struct btd_adapter *adapter);
void btd_adapter_enable_auto_connect(struct btd_adapter *adapter);

typedef ssize_t (*btd_adapter_pin_cb_t) (struct btd_adapter *adapter,
- struct btd_device *dev, char *out);
+ struct btd_device *dev, char *out, gboolean *display);
void btd_adapter_register_pin_cb(struct btd_adapter *adapter,
btd_adapter_pin_cb_t cb);
void btd_adapter_unregister_pin_cb(struct btd_adapter *adapter,
btd_adapter_pin_cb_t cb);
ssize_t btd_adapter_get_pin(struct btd_adapter *adapter, struct btd_device *dev,
- char *pin_buf);
+ char *pin_buf, gboolean *display);

typedef void (*bt_hci_result_t) (uint8_t status, gpointer user_data);

diff --git a/src/event.c b/src/event.c
index a4a60d0..b37f411 100644
--- a/src/event.c
+++ b/src/event.c
@@ -119,12 +119,13 @@ int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba, gboolean secure)
struct btd_device *device;
char pin[17];
ssize_t pinlen;
+ gboolean display = FALSE;

if (!get_adapter_and_device(sba, dba, &adapter, &device, TRUE))
return -ENODEV;

memset(pin, 0, sizeof(pin));
- pinlen = btd_adapter_get_pin(adapter, device, pin);
+ pinlen = btd_adapter_get_pin(adapter, device, pin, &display);
if (pinlen > 0 && (!secure || pinlen == 16)) {
btd_adapter_pincode_reply(adapter, dba, pin, pinlen);
return 0;
--
1.7.7.3


2012-04-05 22:29:36

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 4/8] Add AUTH_TYPE_NOTIFY_PASSKEY to device_request_authentication

This new authentication type accepts a pincode and calls the
DisplayPinCode agent method, a fallback is provided so that if the
method is not implemented the older RequestPinCode method is used
instead.

Due to this fallback, the agent_pincode_cb is used and calling
functions should send the pincode passed to the callback to the
adapter, which may differ from that generated.
---
src/device.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/device.h | 1 +
2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/src/device.c b/src/device.c
index 0a77f80..751f719 100644
--- a/src/device.c
+++ b/src/device.c
@@ -96,6 +96,7 @@ struct authentication_req {
struct agent *agent;
struct btd_device *device;
uint32_t passkey;
+ char *pincode;
gboolean secure;
};

@@ -281,6 +282,8 @@ static void device_free(gpointer user_data)

DBG("%p", device);

+ if (device->authr)
+ g_free(device->authr->pincode);
g_free(device->authr);
g_free(device->path);
g_free(device->alias);
@@ -2525,12 +2528,15 @@ void device_simple_pairing_complete(struct btd_device *device, uint8_t status)
{
struct authentication_req *auth = device->authr;

- if (auth && auth->type == AUTH_TYPE_NOTIFY_PASSKEY && auth->agent)
+ if (auth && (auth->type == AUTH_TYPE_NOTIFY_PASSKEY
+ || auth->type == AUTH_TYPE_NOTIFY_PINCODE) && auth->agent)
agent_cancel(auth->agent);
}

static void device_auth_req_free(struct btd_device *device)
{
+ if (device->authr)
+ g_free(device->authr->pincode);
g_free(device->authr);
device->authr = NULL;
}
@@ -2542,7 +2548,8 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)

DBG("bonding %p status 0x%02x", bonding, status);

- if (auth && auth->type == AUTH_TYPE_NOTIFY_PASSKEY && auth->agent)
+ if (auth && (auth->type == AUTH_TYPE_NOTIFY_PASSKEY
+ || auth->type == AUTH_TYPE_NOTIFY_PINCODE) && auth->agent)
agent_cancel(auth->agent);

if (status) {
@@ -2752,6 +2759,46 @@ done:
device->authr->agent = NULL;
}

+static void display_pincode_cb(struct agent *agent, DBusError *err, void *data)
+{
+ struct authentication_req *auth = data;
+ struct btd_device *device = auth->device;
+ struct btd_adapter *adapter = device_get_adapter(device);
+ struct agent *adapter_agent = adapter_get_agent(adapter);
+
+ if (err && (g_str_equal(DBUS_ERROR_UNKNOWN_METHOD, err->name) ||
+ g_str_equal(DBUS_ERROR_NO_REPLY, err->name))) {
+
+ /* Request a pincode if we fail to display one */
+ if (auth->agent == adapter_agent || adapter_agent == NULL) {
+ if (agent_request_pincode(agent, device, pincode_cb,
+ auth->secure, auth, NULL) < 0)
+ goto done;
+ return;
+ }
+
+ if (agent_display_pincode(adapter_agent, device, auth->pincode,
+ display_pincode_cb, auth, NULL) < 0)
+ goto done;
+
+ auth->agent = adapter_agent;
+ return;
+ }
+
+done:
+ /* No need to reply anything if the authentication already failed */
+ if (auth->cb == NULL)
+ return;
+
+ ((agent_pincode_cb) auth->cb)(agent, err, auth->pincode, device);
+
+ g_free(device->authr->pincode);
+ device->authr->pincode = NULL;
+ device->authr->cb = NULL;
+ device->authr->agent = NULL;
+}
+
+
int device_request_authentication(struct btd_device *device, auth_type_t type,
void *data, gboolean secure, void *cb)
{
@@ -2800,6 +2847,11 @@ int device_request_authentication(struct btd_device *device, auth_type_t type,
auth->passkey = *(uint32_t *)data;
err = agent_display_passkey(agent, device, auth->passkey);
break;
+ case AUTH_TYPE_NOTIFY_PINCODE:
+ auth->pincode = g_strdup((const char *)data);
+ err = agent_display_pincode(agent, device, auth->pincode,
+ display_pincode_cb, auth, NULL);
+ break;
default:
err = -EINVAL;
}
@@ -2840,6 +2892,9 @@ static void cancel_authentication(struct authentication_req *auth)
case AUTH_TYPE_NOTIFY_PASSKEY:
/* User Notify doesn't require any reply */
break;
+ case AUTH_TYPE_NOTIFY_PINCODE:
+ ((agent_pincode_cb) auth->cb)(agent, &err, NULL, device);
+ break;
}

dbus_error_free(&err);
diff --git a/src/device.h b/src/device.h
index 4aca224..690c64d 100644
--- a/src/device.h
+++ b/src/device.h
@@ -31,6 +31,7 @@ typedef enum {
AUTH_TYPE_PASSKEY,
AUTH_TYPE_CONFIRM,
AUTH_TYPE_NOTIFY_PASSKEY,
+ AUTH_TYPE_NOTIFY_PINCODE,
} auth_type_t;

struct btd_device *device_create(DBusConnection *conn,
--
1.7.7.3


2012-04-05 22:29:35

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 3/8] agent: add DisplayPinCode method

In constrast to DisplayPasskey, this sends a UTF-8 string PIN code
to the agent; also we support a callback for the case where the
Agent doesn't implement this new method so we can fallback.
---
src/agent.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/agent.h | 4 ++
2 files changed, 115 insertions(+), 1 deletions(-)

diff --git a/src/agent.c b/src/agent.c
index 9b942e8..23e3b43 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -52,7 +52,8 @@ typedef enum {
AGENT_REQUEST_CONFIRMATION,
AGENT_REQUEST_PINCODE,
AGENT_REQUEST_AUTHORIZE,
- AGENT_REQUEST_CONFIRM_MODE
+ AGENT_REQUEST_CONFIRM_MODE,
+ AGENT_REQUEST_DISPLAY_PINCODE,
} agent_request_type_t;

struct agent {
@@ -699,6 +700,115 @@ int agent_display_passkey(struct agent *agent, struct btd_device *device,
return 0;
}

+static void display_pincode_reply(DBusPendingCall *call, void *user_data)
+{
+ struct agent_request *req = user_data;
+ struct agent *agent = req->agent;
+ DBusMessage *message;
+ DBusError err;
+ agent_cb cb = req->cb;
+
+ /* clear agent->request early; our callback will likely try
+ * another request */
+ agent->request = NULL;
+
+ /* steal_reply will always return non-NULL since the callback
+ * is only called after a reply has been received */
+ message = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&err);
+ if (dbus_set_error_from_message(&err, message)) {
+ error("Agent replied with an error: %s, %s",
+ err.name, err.message);
+
+ cb(agent, &err, req->user_data);
+
+ if (dbus_error_has_name(&err, DBUS_ERROR_NO_REPLY)) {
+ agent_cancel(agent);
+ dbus_message_unref(message);
+ dbus_error_free(&err);
+ return;
+ }
+
+ dbus_error_free(&err);
+ goto done;
+ }
+
+ dbus_error_init(&err);
+ if (!dbus_message_get_args(message, &err, DBUS_TYPE_INVALID)) {
+ error("Wrong reply signature: %s", err.message);
+ cb(agent, &err, req->user_data);
+ dbus_error_free(&err);
+ goto done;
+ }
+
+ cb(agent, NULL, req->user_data);
+done:
+ dbus_message_unref(message);
+
+ agent_request_free(req, TRUE);
+}
+
+static int display_pincode_request_new(struct agent_request *req,
+ const char *device_path,
+ const char *pincode)
+{
+ struct agent *agent = req->agent;
+
+ req->msg = dbus_message_new_method_call(agent->name, agent->path,
+ "org.bluez.Agent", "DisplayPinCode");
+ if (req->msg == NULL) {
+ error("Couldn't allocate D-Bus message");
+ return -ENOMEM;
+ }
+
+ dbus_message_append_args(req->msg,
+ DBUS_TYPE_OBJECT_PATH, &device_path,
+ DBUS_TYPE_STRING, &pincode,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send_with_reply(connection, req->msg,
+ &req->call, REQUEST_TIMEOUT) == FALSE) {
+ error("D-Bus send failed");
+ return -EIO;
+ }
+
+ dbus_pending_call_set_notify(req->call, display_pincode_reply,
+ req, NULL);
+
+ return 0;
+}
+
+int agent_display_pincode(struct agent *agent, struct btd_device *device,
+ const char *pincode, agent_cb cb,
+ void *user_data, GDestroyNotify destroy)
+{
+ struct agent_request *req;
+ const gchar *dev_path = device_get_path(device);
+ int err;
+
+ if (agent->request)
+ return -EBUSY;
+
+ DBG("Calling Agent.DisplayPinCode: name=%s, path=%s, pincode=%s",
+ agent->name, agent->path, pincode);
+
+ req = agent_request_new(agent, AGENT_REQUEST_DISPLAY_PINCODE, cb,
+ user_data, destroy);
+
+ err = display_pincode_request_new(req, dev_path, pincode);
+ if (err < 0)
+ goto failed;
+
+ agent->request = req;
+
+ return 0;
+
+failed:
+ agent_request_free(req, FALSE);
+ return err;
+}
+
uint8_t agent_get_io_capability(struct agent *agent)
{
return agent->capability;
diff --git a/src/agent.h b/src/agent.h
index f62bf3b..69ad42b 100644
--- a/src/agent.h
+++ b/src/agent.h
@@ -64,6 +64,10 @@ int agent_request_confirmation(struct agent *agent, struct btd_device *device,
int agent_display_passkey(struct agent *agent, struct btd_device *device,
uint32_t passkey);

+int agent_display_pincode(struct agent *agent, struct btd_device *device,
+ const char *pincode, agent_cb cb,
+ void *user_data, GDestroyNotify destroy);
+
int agent_cancel(struct agent *agent);

gboolean agent_is_busy(struct agent *agent, void *user_data);
--
1.7.7.3


2012-04-05 22:29:34

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 2/8] Pass passkey by pointer rather than by value

This allows alternate data of a different type to be passed to
device_request_authentication() for other notification types such
as those that require a PIN.
---
src/device.c | 9 +++++----
src/device.h | 2 +-
src/event.c | 8 ++++----
3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/device.c b/src/device.c
index 0ae52ce..0a77f80 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2753,7 +2753,7 @@ done:
}

int device_request_authentication(struct btd_device *device, auth_type_t type,
- uint32_t passkey, gboolean secure, void *cb)
+ void *data, gboolean secure, void *cb)
{
struct authentication_req *auth;
struct agent *agent;
@@ -2779,7 +2779,6 @@ int device_request_authentication(struct btd_device *device, auth_type_t type,
auth->device = device;
auth->cb = cb;
auth->type = type;
- auth->passkey = passkey;
auth->secure = secure;
device->authr = auth;

@@ -2793,11 +2792,13 @@ int device_request_authentication(struct btd_device *device, auth_type_t type,
auth, NULL);
break;
case AUTH_TYPE_CONFIRM:
- err = agent_request_confirmation(agent, device, passkey,
+ auth->passkey = *(uint32_t *)data;
+ err = agent_request_confirmation(agent, device, auth->passkey,
confirm_cb, auth, NULL);
break;
case AUTH_TYPE_NOTIFY_PASSKEY:
- err = agent_display_passkey(agent, device, passkey);
+ auth->passkey = *(uint32_t *)data;
+ err = agent_display_passkey(agent, device, auth->passkey);
break;
default:
err = -EINVAL;
diff --git a/src/device.h b/src/device.h
index d5fdf45..4aca224 100644
--- a/src/device.h
+++ b/src/device.h
@@ -84,7 +84,7 @@ gboolean device_is_creating(struct btd_device *device, const char *sender);
gboolean device_is_bonding(struct btd_device *device, const char *sender);
void device_cancel_bonding(struct btd_device *device, uint8_t status);
int device_request_authentication(struct btd_device *device, auth_type_t type,
- uint32_t passkey, gboolean secure, void *cb);
+ void *data, gboolean secure, void *cb);
void device_cancel_authentication(struct btd_device *device, gboolean aborted);
gboolean device_is_authenticating(struct btd_device *device);
gboolean device_is_authorizing(struct btd_device *device);
diff --git a/src/event.c b/src/event.c
index 3259e7d..a4a60d0 100644
--- a/src/event.c
+++ b/src/event.c
@@ -130,7 +130,7 @@ int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba, gboolean secure)
return 0;
}

- return device_request_authentication(device, AUTH_TYPE_PINCODE, 0,
+ return device_request_authentication(device, AUTH_TYPE_PINCODE, NULL,
secure, pincode_cb);
}

@@ -179,7 +179,7 @@ int btd_event_user_confirm(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey)
return -ENODEV;

return device_request_authentication(device, AUTH_TYPE_CONFIRM,
- passkey, FALSE, confirm_cb);
+ &passkey, FALSE, confirm_cb);
}

int btd_event_user_passkey(bdaddr_t *sba, bdaddr_t *dba)
@@ -190,7 +190,7 @@ int btd_event_user_passkey(bdaddr_t *sba, bdaddr_t *dba)
if (!get_adapter_and_device(sba, dba, &adapter, &device, TRUE))
return -ENODEV;

- return device_request_authentication(device, AUTH_TYPE_PASSKEY, 0,
+ return device_request_authentication(device, AUTH_TYPE_PASSKEY, NULL,
FALSE, passkey_cb);
}

@@ -203,7 +203,7 @@ int btd_event_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey)
return -ENODEV;

return device_request_authentication(device, AUTH_TYPE_NOTIFY_PASSKEY,
- passkey, FALSE, NULL);
+ &passkey, FALSE, NULL);
}

void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
--
1.7.7.3


2012-04-05 22:29:33

by Scott James Remnant

[permalink] [raw]
Subject: [PATCHv3 1/8] Rename AUTH_TYPE_NOTIFY to AUTH_TYPE_NOTIFY_PASSKEY

This makes room for additional notification types to be added.
---
src/device.c | 8 ++++----
src/device.h | 2 +-
src/event.c | 4 ++--
3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/device.c b/src/device.c
index df3fbac..0ae52ce 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2525,7 +2525,7 @@ void device_simple_pairing_complete(struct btd_device *device, uint8_t status)
{
struct authentication_req *auth = device->authr;

- if (auth && auth->type == AUTH_TYPE_NOTIFY && auth->agent)
+ if (auth && auth->type == AUTH_TYPE_NOTIFY_PASSKEY && auth->agent)
agent_cancel(auth->agent);
}

@@ -2542,7 +2542,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t status)

DBG("bonding %p status 0x%02x", bonding, status);

- if (auth && auth->type == AUTH_TYPE_NOTIFY && auth->agent)
+ if (auth && auth->type == AUTH_TYPE_NOTIFY_PASSKEY && auth->agent)
agent_cancel(auth->agent);

if (status) {
@@ -2796,7 +2796,7 @@ int device_request_authentication(struct btd_device *device, auth_type_t type,
err = agent_request_confirmation(agent, device, passkey,
confirm_cb, auth, NULL);
break;
- case AUTH_TYPE_NOTIFY:
+ case AUTH_TYPE_NOTIFY_PASSKEY:
err = agent_display_passkey(agent, device, passkey);
break;
default:
@@ -2836,7 +2836,7 @@ static void cancel_authentication(struct authentication_req *auth)
case AUTH_TYPE_PASSKEY:
((agent_passkey_cb) auth->cb)(agent, &err, 0, device);
break;
- case AUTH_TYPE_NOTIFY:
+ case AUTH_TYPE_NOTIFY_PASSKEY:
/* User Notify doesn't require any reply */
break;
}
diff --git a/src/device.h b/src/device.h
index f3d6c70..d5fdf45 100644
--- a/src/device.h
+++ b/src/device.h
@@ -30,7 +30,7 @@ typedef enum {
AUTH_TYPE_PINCODE,
AUTH_TYPE_PASSKEY,
AUTH_TYPE_CONFIRM,
- AUTH_TYPE_NOTIFY,
+ AUTH_TYPE_NOTIFY_PASSKEY,
} auth_type_t;

struct btd_device *device_create(DBusConnection *conn,
diff --git a/src/event.c b/src/event.c
index 78d2757..3259e7d 100644
--- a/src/event.c
+++ b/src/event.c
@@ -202,8 +202,8 @@ int btd_event_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey)
if (!get_adapter_and_device(sba, dba, &adapter, &device, TRUE))
return -ENODEV;

- return device_request_authentication(device, AUTH_TYPE_NOTIFY, passkey,
- FALSE, NULL);
+ return device_request_authentication(device, AUTH_TYPE_NOTIFY_PASSKEY,
+ passkey, FALSE, NULL);
}

void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
--
1.7.7.3