Use hci_send_cmd instead of hci_send_req for authentication
In addition to blocking the mainloop hci_send_req changes the socket
filters which makes it unusable for the per-adapter HCI socket in
hciops.c. Using hci_send_cmd makes much more sense here.
diff --git a/plugins/hciops.c b/plugins/hciops.c
index 9abe477..cdbd261 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2329,33 +2329,19 @@
return 0;
}
-static int hciops_request_authentication(int index, uint16_t handle,
- uint8_t *status)
+static int hciops_request_authentication(int index, uint16_t handle)
{
- struct hci_request rq;
auth_requested_cp cp;
- evt_cmd_status rp;
- memset(&rp, 0, sizeof(rp));
+ DBG("");
memset(&cp, 0, sizeof(cp));
cp.handle = htobs(handle);
- memset(&rq, 0, sizeof(rq));
- rq.ogf = OGF_LINK_CTL;
- rq.ocf = OCF_AUTH_REQUESTED;
- rq.cparam = &cp;
- rq.clen = AUTH_REQUESTED_CP_SIZE;
- rq.rparam = &rp;
- rq.rlen = EVT_CMD_STATUS_SIZE;
- rq.event = EVT_CMD_STATUS;
-
- if (hci_send_req(SK(index), &rq, HCI_REQ_TIMEOUT) < 0)
+ if (hci_send_cmd(SK(index), OGF_LINK_CTL, OCF_AUTH_REQUESTED,
+ AUTH_REQUESTED_CP_SIZE, &cp) < 0)
return -errno;
- if (status)
- *status = rp.status;
-
return 0;
}
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 3d96638..6a7013f 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -704,8 +704,7 @@
return -ENOSYS;
}
-static int mgmt_request_authentication(int index, uint16_t handle,
- uint8_t *status)
+static int mgmt_request_authentication(int index, uint16_t handle)
{
DBG("index %d handle %u", index, handle);
return -ENOSYS;
diff --git a/src/adapter.c b/src/adapter.c
index 6b4a354..3edbdd9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3648,10 +3648,9 @@
}
int btd_adapter_request_authentication(struct btd_adapter *adapter,
- uint16_t handle, uint8_t *status)
+ uint16_t handle)
{
- return adapter_ops->request_authentication(adapter->dev_id,
- handle, status);
+ return adapter_ops->request_authentication(adapter->dev_id, handle);
}
int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
diff --git a/src/adapter.h b/src/adapter.h
index de6a6f5..40c073e 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -220,8 +220,7 @@
int (*read_link_policy) (int index);
int (*disconnect) (int index, uint16_t handle);
int (*remove_bonding) (int index, bdaddr_t *bdaddr);
- int (*request_authentication) (int index, uint16_t handle,
- uint8_t *status);
+ int (*request_authentication) (int index, uint16_t handle);
int (*pincode_reply) (int index, bdaddr_t *bdaddr, const char *pin);
int (*confirm_reply) (int index, bdaddr_t *bdaddr, gboolean success);
int (*passkey_reply) (int index, bdaddr_t *bdaddr, uint32_t passkey);
@@ -266,7 +265,7 @@
int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr);
int btd_adapter_request_authentication(struct btd_adapter *adapter,
- uint16_t handle, uint8_t *status);
+ uint16_t handle);
int btd_adapter_pincode_reply(struct btd_adapter *adapter, bdaddr_t *bdaddr,
const char *pin);
diff --git a/src/device.c b/src/device.c
index 4427cd4..534ab38 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1855,30 +1855,10 @@
return bonding;
}
-static uint8_t device_authentication_requested(struct btd_device *device,
- int handle)
-{
- uint8_t status;
- int err;
-
- err = btd_adapter_request_authentication(device->adapter, handle,
- &status);
- if (err < 0) {
- error("Sending authentication request failed: %s (%d)",
- strerror(-err), -err);
- return HCI_UNSPECIFIED_ERROR;
- }
-
- info("Authentication requested");
-
- return status;
-}
-
static void bonding_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
struct btd_device *device = user_data;
uint16_t handle;
- int status;
if (!device->bonding) {
if (!err)
@@ -1895,19 +1875,17 @@
BT_IO_OPT_INVALID)) {
error("Unable to get connection handle: %s", err->message);
g_error_free(err);
- status = -errno;
goto failed;
}
- status = device_authentication_requested(device, handle);
- if (status != 0)
+ if (btd_adapter_request_authentication(device->adapter, handle) < 0)
goto failed;
return;
failed:
g_io_channel_shutdown(io, TRUE, NULL);
- device_cancel_bonding(device, status);
+ device_cancel_bonding(device, HCI_UNSPECIFIED_ERROR);
}
static void create_bond_req_exit(DBusConnection *conn, void *user_data)