diff --git a/src/device.c b/src/device.c
index a5bdf4c..29b76cb 100644
--- a/src/device.c
+++ b/src/device.c
struct authentication_req {
auth_type_t type;
- void *cb;
struct agent *agent;
struct btd_device *device;
uint32_t passkey;
bonding_request_free(bonding);
}
-static void pincode_cb(struct agent *agent, DBusError *err,
- const char *pincode, void *data)
+static void pincode_cb(struct agent *agent, DBusError *err, const char *pin,
+ void *data)
{
struct authentication_req *auth = data;
struct btd_device *device = auth->device;
done:
/* No need to reply anything if the authentication already failed */
- if (auth->cb == NULL)
+ if (auth->agent == NULL)
return;
- ((agent_pincode_cb) auth->cb)(agent, err, pincode, device);
+ btd_adapter_pincode_reply(device->adapter, device_get_address(device),
+ pin, pin ? strlen(pin) : 0);
- device->authr->cb = NULL;
device->authr->agent = NULL;
}
done:
/* No need to reply anything if the authentication already failed */
- if (auth->cb == NULL)
+ if (auth->agent == NULL)
return;
- ((agent_cb) auth->cb)(agent, err, device);
+ btd_adapter_confirm_reply(device->adapter, device_get_address(device),
+ device_get_addr_type(device),
+ err ? FALSE : TRUE);
- device->authr->cb = NULL;
device->authr->agent = NULL;
}
done:
/* No need to reply anything if the authentication already failed */
- if (auth->cb == NULL)
+ if (auth->agent == NULL)
return;
- ((agent_passkey_cb) auth->cb)(agent, err, passkey, device);
+ if (err)
+ passkey = INVALID_PASSKEY;
+
+ btd_adapter_passkey_reply(device->adapter, device_get_address(device),
+ device_get_addr_type(device), passkey);
- device->authr->cb = NULL;
device->authr->agent = NULL;
}
done:
/* No need to reply anything if the authentication already failed */
- if (auth->cb == NULL)
+ if (auth->agent == NULL)
return;
- ((agent_pincode_cb) auth->cb)(agent, err, auth->pincode, device);
+ pincode_cb(agent, err, auth->pincode, device);
g_free(device->authr->pincode);
device->authr->pincode = NULL;
- device->authr->cb = NULL;
device->authr->agent = NULL;
}
static struct authentication_req *new_auth(struct btd_device *device,
- auth_type_t type, gboolean secure,
- void *cb)
+ auth_type_t type, gboolean secure)
{
struct authentication_req *auth;
struct agent *agent;
auth = g_new0(struct authentication_req, 1);
auth->agent = agent;
auth->device = device;
- auth->cb = cb;
auth->type = type;
auth->secure = secure;
device->authr = auth;
return auth;
}
-int device_request_pincode(struct btd_device *device, gboolean secure,
- void *cb)
+int device_request_pincode(struct btd_device *device, gboolean secure)
{
struct authentication_req *auth;
int err;
- auth = new_auth(device, AUTH_TYPE_PINCODE, secure, cb);
+ auth = new_auth(device, AUTH_TYPE_PINCODE, secure);
if (!auth)
return -EPERM;
return err;
}
-int device_request_passkey(struct btd_device *device, void *cb)
+int device_request_passkey(struct btd_device *device)
{
struct authentication_req *auth;
int err;
- auth = new_auth(device, AUTH_TYPE_PASSKEY, FALSE, cb);
+ auth = new_auth(device, AUTH_TYPE_PASSKEY, FALSE);
if (!auth)
return -EPERM;
return err;
}
-int device_confirm_passkey(struct btd_device *device, uint32_t passkey,
- void *cb)
+int device_confirm_passkey(struct btd_device *device, uint32_t passkey)
+
{
struct authentication_req *auth;
int err;
- auth = new_auth(device, AUTH_TYPE_CONFIRM, FALSE, cb);
+ auth = new_auth(device, AUTH_TYPE_CONFIRM, FALSE);
if (!auth)
return -EPERM;
if (auth->type != AUTH_TYPE_NOTIFY_PASSKEY)
return -EPERM;
} else {
- auth = new_auth(device, AUTH_TYPE_NOTIFY_PASSKEY, FALSE, NULL);
+ auth = new_auth(device, AUTH_TYPE_NOTIFY_PASSKEY, FALSE);
if (!auth)
return -EPERM;
}
}
int device_notify_pincode(struct btd_device *device, gboolean secure,
- const char *pincode, void *cb)
+ const char *pincode)
{
struct authentication_req *auth;
int err;
- auth = new_auth(device, AUTH_TYPE_NOTIFY_PINCODE, secure, cb);
+ auth = new_auth(device, AUTH_TYPE_NOTIFY_PINCODE, secure);
if (!auth)
return -EPERM;
struct agent *agent;
DBusError err;
- if (!auth || !auth->cb)
+ if (!auth || !auth->agent)
return;
device = auth->device;
agent = auth->agent;
+ auth->agent = NULL;
dbus_error_init(&err);
dbus_set_error_const(&err, "org.bluez.Error.Canceled", NULL);
switch (auth->type) {
case AUTH_TYPE_PINCODE:
- ((agent_pincode_cb) auth->cb)(agent, &err, NULL, device);
+ pincode_cb(agent, &err, NULL, device);
break;
case AUTH_TYPE_CONFIRM:
- ((agent_cb) auth->cb)(agent, &err, device);
+ confirm_cb(agent, &err, device);
break;
case AUTH_TYPE_PASSKEY:
- ((agent_passkey_cb) auth->cb)(agent, &err, 0, device);
+ passkey_cb(agent, &err, 0, device);
break;
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);
+ pincode_cb(agent, &err, NULL, device);
break;
}
dbus_error_free(&err);
- auth->cb = NULL;
}
void device_cancel_authentication(struct btd_device *device, gboolean aborted)
diff --git a/src/device.h b/src/device.h
index 703dfcf..1e3dced 100644
--- a/src/device.h
+++ b/src/device.h
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_pincode(struct btd_device *device, gboolean secure,
- void *cb);
-int device_request_passkey(struct btd_device *device, void *cb);
-int device_confirm_passkey(struct btd_device *device, uint32_t passkey,
- void *cb);
+int device_request_pincode(struct btd_device *device, gboolean secure);
+int device_request_passkey(struct btd_device *device);
+int device_confirm_passkey(struct btd_device *device, uint32_t passkey);
int device_notify_passkey(struct btd_device *device, uint32_t passkey,
uint8_t entered);
int device_notify_pincode(struct btd_device *device, gboolean secure,
- const char *pincode, void *cb);
+ const char *pincode);
void device_cancel_authentication(struct btd_device *device, gboolean aborted);
gboolean device_is_authenticating(struct btd_device *device);
void device_add_connection(struct btd_device *device);
diff --git a/src/event.c b/src/event.c
index f8b8242..ee8ed4e 100644
--- a/src/event.c
+++ b/src/event.c
return TRUE;
}
-static void pincode_cb(struct agent *agent, DBusError *derr,
- const char *pincode, struct btd_device *device)
-{
- struct btd_adapter *adapter = device_get_adapter(device);
- int err;
-
- if (derr) {
- err = btd_adapter_pincode_reply(adapter,
- device_get_address(device), NULL, 0);
- if (err < 0)
- goto fail;
- return;
- }
-
- err = btd_adapter_pincode_reply(adapter, device_get_address(device),
- pincode, pincode ? strlen(pincode) : 0);
- if (err < 0)
- goto fail;
-
- return;
-
-fail:
- error("Sending PIN code reply failed: %s (%d)", strerror(-err), -err);
-}
-
int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba, gboolean secure)
{
struct btd_adapter *adapter;
pinlen = btd_adapter_get_pin(adapter, device, pin, &display);
if (pinlen > 0 && (!secure || pinlen == 16)) {
if (display && device_is_bonding(device, NULL))
- return device_notify_pincode(device, secure, pin,
- pincode_cb);
+ return device_notify_pincode(device, secure, pin);
btd_adapter_pincode_reply(adapter, dba, pin, pinlen);
return 0;
}
- return device_request_pincode(device, secure, pincode_cb);
-}
-
-static int confirm_reply(struct btd_adapter *adapter,
- struct btd_device *device, gboolean success)
-{
- return btd_adapter_confirm_reply(adapter, device_get_address(device),
- device_get_addr_type(device),
- success);
-}
-
-static void confirm_cb(struct agent *agent, DBusError *err, void *user_data)
-{
- struct btd_device *device = user_data;
- struct btd_adapter *adapter = device_get_adapter(device);
- gboolean success = (err == NULL) ? TRUE : FALSE;
-
- confirm_reply(adapter, device, success);
-}
-
-static void passkey_cb(struct agent *agent, DBusError *err, uint32_t passkey,
- void *user_data)
-{
- struct btd_device *device = user_data;
- struct btd_adapter *adapter = device_get_adapter(device);
-
- if (err)
- passkey = INVALID_PASSKEY;
-
- btd_adapter_passkey_reply(adapter, device_get_address(device),
- device_get_addr_type(device), passkey);
+ return device_request_pincode(device, secure);
}
int btd_event_user_confirm(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey)
if (!get_adapter_and_device(sba, dba, &adapter, &device, TRUE))
return -ENODEV;
- return device_confirm_passkey(device, passkey, confirm_cb);
+ return device_confirm_passkey(device, passkey);
}
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_passkey(device, passkey_cb);
+ return device_request_passkey(device);
}
int btd_event_user_notify(bdaddr_t *sba, bdaddr_t *dba, uint32_t passkey,