Commit 3b4a39af authored by John W. Linville's avatar John W. Linville
parents b0fd49b7 1c2e0041
...@@ -1144,6 +1144,12 @@ struct extended_inquiry_info { ...@@ -1144,6 +1144,12 @@ struct extended_inquiry_info {
__u8 data[240]; __u8 data[240];
} __packed; } __packed;
#define HCI_EV_KEY_REFRESH_COMPLETE 0x30
struct hci_ev_key_refresh_complete {
__u8 status;
__le16 handle;
} __packed;
#define HCI_EV_IO_CAPA_REQUEST 0x31 #define HCI_EV_IO_CAPA_REQUEST 0x31
struct hci_ev_io_capa_request { struct hci_ev_io_capa_request {
bdaddr_t bdaddr; bdaddr_t bdaddr;
......
...@@ -3043,6 +3043,50 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct ...@@ -3043,6 +3043,50 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
} }
static void hci_key_refresh_complete_evt(struct hci_dev *hdev,
struct sk_buff *skb)
{
struct hci_ev_key_refresh_complete *ev = (void *) skb->data;
struct hci_conn *conn;
BT_DBG("%s status %u handle %u", hdev->name, ev->status,
__le16_to_cpu(ev->handle));
hci_dev_lock(hdev);
conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
if (!conn)
goto unlock;
if (!ev->status)
conn->sec_level = conn->pending_sec_level;
clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
if (ev->status && conn->state == BT_CONNECTED) {
hci_acl_disconn(conn, HCI_ERROR_AUTH_FAILURE);
hci_conn_put(conn);
goto unlock;
}
if (conn->state == BT_CONFIG) {
if (!ev->status)
conn->state = BT_CONNECTED;
hci_proto_connect_cfm(conn, ev->status);
hci_conn_put(conn);
} else {
hci_auth_cfm(conn, ev->status);
hci_conn_hold(conn);
conn->disc_timeout = HCI_DISCONN_TIMEOUT;
hci_conn_put(conn);
}
unlock:
hci_dev_unlock(hdev);
}
static inline u8 hci_get_auth_req(struct hci_conn *conn) static inline u8 hci_get_auth_req(struct hci_conn *conn)
{ {
/* If remote requests dedicated bonding follow that lead */ /* If remote requests dedicated bonding follow that lead */
...@@ -3559,6 +3603,10 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -3559,6 +3603,10 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
hci_extended_inquiry_result_evt(hdev, skb); hci_extended_inquiry_result_evt(hdev, skb);
break; break;
case HCI_EV_KEY_REFRESH_COMPLETE:
hci_key_refresh_complete_evt(hdev, skb);
break;
case HCI_EV_IO_CAPA_REQUEST: case HCI_EV_IO_CAPA_REQUEST:
hci_io_capa_request_evt(hdev, skb); hci_io_capa_request_evt(hdev, skb);
break; break;
......
...@@ -1295,7 +1295,12 @@ static void security_timeout(struct work_struct *work) ...@@ -1295,7 +1295,12 @@ static void security_timeout(struct work_struct *work)
struct l2cap_conn *conn = container_of(work, struct l2cap_conn, struct l2cap_conn *conn = container_of(work, struct l2cap_conn,
security_timer.work); security_timer.work);
BT_DBG("conn %p", conn);
if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->flags)) {
smp_chan_destroy(conn);
l2cap_conn_del(conn->hcon, ETIMEDOUT); l2cap_conn_del(conn->hcon, ETIMEDOUT);
}
} }
static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status) static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
......
...@@ -1873,6 +1873,22 @@ static void pairing_complete_cb(struct hci_conn *conn, u8 status) ...@@ -1873,6 +1873,22 @@ static void pairing_complete_cb(struct hci_conn *conn, u8 status)
pairing_complete(cmd, mgmt_status(status)); pairing_complete(cmd, mgmt_status(status));
} }
static void le_connect_complete_cb(struct hci_conn *conn, u8 status)
{
struct pending_cmd *cmd;
BT_DBG("status %u", status);
if (!status)
return;
cmd = find_pairing(conn);
if (!cmd)
BT_DBG("Unable to find a pending command");
else
pairing_complete(cmd, mgmt_status(status));
}
static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
u16 len) u16 len)
{ {
...@@ -1934,6 +1950,8 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data, ...@@ -1934,6 +1950,8 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
/* For LE, just connecting isn't a proof that the pairing finished */ /* For LE, just connecting isn't a proof that the pairing finished */
if (cp->addr.type == BDADDR_BREDR) if (cp->addr.type == BDADDR_BREDR)
conn->connect_cfm_cb = pairing_complete_cb; conn->connect_cfm_cb = pairing_complete_cb;
else
conn->connect_cfm_cb = le_connect_complete_cb;
conn->security_cfm_cb = pairing_complete_cb; conn->security_cfm_cb = pairing_complete_cb;
conn->disconn_cfm_cb = pairing_complete_cb; conn->disconn_cfm_cb = pairing_complete_cb;
......
...@@ -648,7 +648,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -648,7 +648,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
auth |= (req->auth_req | rsp->auth_req) & SMP_AUTH_MITM; auth |= (req->auth_req | rsp->auth_req) & SMP_AUTH_MITM;
ret = tk_request(conn, 0, auth, rsp->io_capability, req->io_capability); ret = tk_request(conn, 0, auth, req->io_capability, rsp->io_capability);
if (ret) if (ret)
return SMP_UNSPECIFIED; return SMP_UNSPECIFIED;
...@@ -703,7 +703,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -703,7 +703,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
return 0; return 0;
} }
static u8 smp_ltk_encrypt(struct l2cap_conn *conn) static u8 smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
{ {
struct smp_ltk *key; struct smp_ltk *key;
struct hci_conn *hcon = conn->hcon; struct hci_conn *hcon = conn->hcon;
...@@ -712,6 +712,9 @@ static u8 smp_ltk_encrypt(struct l2cap_conn *conn) ...@@ -712,6 +712,9 @@ static u8 smp_ltk_encrypt(struct l2cap_conn *conn)
if (!key) if (!key)
return 0; return 0;
if (sec_level > BT_SECURITY_MEDIUM && !key->authenticated)
return 0;
if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags))
return 1; return 1;
...@@ -732,7 +735,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) ...@@ -732,7 +735,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
hcon->pending_sec_level = authreq_to_seclevel(rp->auth_req); hcon->pending_sec_level = authreq_to_seclevel(rp->auth_req);
if (smp_ltk_encrypt(conn)) if (smp_ltk_encrypt(conn, hcon->pending_sec_level))
return 0; return 0;
if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags)) if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags))
...@@ -771,7 +774,7 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) ...@@ -771,7 +774,7 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)
return 1; return 1;
if (hcon->link_mode & HCI_LM_MASTER) if (hcon->link_mode & HCI_LM_MASTER)
if (smp_ltk_encrypt(conn)) if (smp_ltk_encrypt(conn, sec_level))
goto done; goto done;
if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags)) if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment