| From 888f24266b8ff06d7007afb5e6a38ba621750451 Mon Sep 17 00:00:00 2001 |
| From: Scott James Remnant <scott@netsplit.com> |
| Date: Mon, 23 Jan 2012 10:43:48 -0800 |
| Subject: [PATCH 02/13] 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 92c13f5..8a2ae9d 100644 |
| --- a/src/device.c |
| +++ b/src/device.c |
| @@ -2681,7 +2681,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; |
| @@ -2707,7 +2707,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; |
| |
| @@ -2721,11 +2720,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 aa7f2f1..998aee7 100644 |
| --- a/src/device.h |
| +++ b/src/device.h |
| @@ -83,7 +83,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 95cdbdb..7d66b6d 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 |
| |