From 18f0cdaac11b07ad3a209bd6ba03ced11e99b714 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 14 Mar 2014 13:16:37 +0200 Subject: [PATCH] emulator/btdev: Add support for negative LTK reply --- emulator/btdev.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/emulator/btdev.c b/emulator/btdev.c index c127c0b55..6a3b163a6 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -1561,6 +1561,32 @@ static void le_encrypt_complete(struct btdev *btdev) send_event(remote, BT_HCI_EVT_ENCRYPT_CHANGE, &ev, sizeof(ev)); } +static void ltk_neg_reply_complete(struct btdev *btdev) +{ + struct bt_hci_rsp_le_ltk_req_neg_reply rp; + struct bt_hci_evt_encrypt_change ev; + struct btdev *remote = btdev->conn; + + memset(&rp, 0, sizeof(rp)); + rp.handle = cpu_to_le16(42); + + if (!remote) { + rp.status = BT_HCI_ERR_UNKNOWN_CONN_ID; + cmd_complete(btdev, BT_HCI_CMD_LE_LTK_REQ_NEG_REPLY, &rp, + sizeof(rp)); + return; + } + + rp.status = BT_HCI_ERR_SUCCESS; + cmd_complete(btdev, BT_HCI_CMD_LE_LTK_REQ_NEG_REPLY, &rp, sizeof(rp)); + + memset(&ev, 0, sizeof(ev)); + ev.status = BT_HCI_ERR_PIN_OR_KEY_MISSING; + ev.handle = cpu_to_le16(42); + + send_event(remote, BT_HCI_EVT_ENCRYPT_CHANGE, &ev, sizeof(ev)); +} + static void default_cmd(struct btdev *btdev, uint16_t opcode, const void *data, uint8_t len) { @@ -2526,6 +2552,12 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode, le_encrypt_complete(btdev); break; + case BT_HCI_CMD_LE_LTK_REQ_NEG_REPLY: + if (btdev->type == BTDEV_TYPE_BREDR) + goto unsupported; + ltk_neg_reply_complete(btdev); + break; + case BT_HCI_CMD_SETUP_SYNC_CONN: if (btdev->type == BTDEV_TYPE_LE) goto unsupported; -- 2.11.0