diff --git a/src/device.c b/src/device.c
index 7d64eb8..b08d72c 100644
--- a/src/device.c
+++ b/src/device.c
struct agent *agent;
struct btd_device *device;
uint32_t passkey;
+ char *pincode;
gboolean secure;
};
DBG("%p", device);
+ if (device->authr)
+ g_free(device->authr->pincode);
g_free(device->authr);
g_free(device->path);
g_free(device->alias);
{
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;
}
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) {
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)
{
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;
}
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
AUTH_TYPE_PASSKEY,
AUTH_TYPE_CONFIRM,
AUTH_TYPE_NOTIFY_PASSKEY,
+ AUTH_TYPE_NOTIFY_PINCODE,
} auth_type_t;
struct btd_device *device_create(DBusConnection *conn,