Move authentication request to hciops

This commit is contained in:
Johan Hedberg 2010-10-01 15:15:52 +03:00
parent 1bf7ec6b5c
commit 424ffb2640
4 changed files with 65 additions and 42 deletions

View File

@ -1067,6 +1067,47 @@ static int hciops_remove_bonding(int index, bdaddr_t *bdaddr)
return err;
}
static int hciops_request_authentication(int index, uint16_t handle,
uint8_t *status)
{
struct hci_request rq;
auth_requested_cp cp;
evt_cmd_status rp;
int dd, err;
dd = hci_open_dev(index);
if (dd < 0)
return -errno;
memset(&rp, 0, sizeof(rp));
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(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
err = -errno;
goto fail;
}
if (status)
*status = rp.status;
err = 0;
fail:
hci_close_dev(dd);
return err;
}
static struct btd_adapter_ops hci_ops = {
.setup = hciops_setup,
.cleanup = hciops_cleanup,
@ -1100,6 +1141,7 @@ static struct btd_adapter_ops hci_ops = {
.read_link_policy = hciops_read_link_policy,
.disconnect = hciops_disconnect,
.remove_bonding = hciops_remove_bonding,
.request_authentication = hciops_request_authentication,
};
static int hciops_init(void)

View File

@ -3491,3 +3491,10 @@ int btd_adapter_remove_bonding(struct btd_adapter *adapter, bdaddr_t *bdaddr)
{
return adapter_ops->remove_bonding(adapter->dev_id, bdaddr);
}
int btd_adapter_request_authentication(struct btd_adapter *adapter,
uint16_t handle, uint8_t *status)
{
return adapter_ops->request_authentication(adapter->dev_id,
handle, status);
}

View File

@ -206,6 +206,8 @@ struct btd_adapter_ops {
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 btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
@ -238,3 +240,6 @@ int btd_adapter_disconnect_device(struct btd_adapter *adapter,
uint16_t handle);
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);

View File

@ -1853,54 +1853,23 @@ proceed:
return bonding;
}
static int device_authentication_requested(struct btd_device *device,
int handle)
static uint8_t device_authentication_requested(struct btd_device *device,
int handle)
{
struct hci_request rq;
auth_requested_cp cp;
evt_cmd_status rp;
int dd;
uint8_t status;
int err;
dd = hci_open_dev(adapter_get_dev_id(device->adapter));
if (dd < 0) {
int err = -errno;
error("Unable to open adapter: %s(%d)", strerror(-err), -err);
return err;
}
memset(&rp, 0, sizeof(rp));
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(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
int err = -errno;
error("Unable to send HCI request: %s (%d)",
strerror(-err), -err);
hci_close_dev(dd);
return err;
}
if (rp.status) {
error("HCI_Authentication_Requested failed with status 0x%02x",
rp.status);
hci_close_dev(dd);
return rp.status;
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");
hci_close_dev(dd);
return 0;
return status;
}
static void bonding_connect_cb(GIOChannel *io, GError *err, gpointer user_data)