From 9980744cd437b3d22128af06e08feb57ae8dc24a Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 10 Jan 2014 15:06:19 +0200 Subject: [PATCH] emulator/bthost: Add basic IO Capability Request & Response handling --- emulator/bthost.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/emulator/bthost.c b/emulator/bthost.c index 98a920e58..68a775cd2 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -165,6 +165,19 @@ static struct btconn *bthost_find_conn(struct bthost *bthost, uint16_t handle) return NULL; } +static struct btconn *bthost_find_conn_by_bdaddr(struct bthost *bthost, + const uint8_t *bdaddr) +{ + struct btconn *conn; + + for (conn = bthost->conns; conn != NULL; conn = conn->next) { + if (!memcmp(conn->bdaddr, bdaddr, 6)) + return conn; + } + + return NULL; +} + static struct l2conn *bthost_add_l2cap_conn(struct bthost *bthost, struct btconn *conn, uint16_t scid, uint16_t dcid, @@ -730,6 +743,43 @@ static void evt_encrypt_change(struct bthost *bthost, const void *data, conn->encr_mode = ev->encr_mode; } +static void evt_io_cap_response(struct bthost *bthost, const void *data, + uint8_t len) +{ + const struct bt_hci_evt_io_capability_response *ev = data; + struct btconn *conn; + + if (len < sizeof(*ev)) + return; + + conn = bthost_find_conn_by_bdaddr(bthost, ev->bdaddr); + if (!conn) + return; +} + +static void evt_io_cap_request(struct bthost *bthost, const void *data, + uint8_t len) +{ + const struct bt_hci_evt_io_capability_request *ev = data; + struct bt_hci_cmd_io_capability_request_reply cp; + struct btconn *conn; + + if (len < sizeof(*ev)) + return; + + conn = bthost_find_conn_by_bdaddr(bthost, ev->bdaddr); + if (!conn) + return; + + memcpy(cp.bdaddr, ev->bdaddr, 6); + cp.capability = 0x03; + cp.oob_data = 0x00; + cp.authentication = 0x00; + + send_command(bthost, BT_HCI_CMD_IO_CAPABILITY_REQUEST_REPLY, + &cp, sizeof(cp)); +} + static void evt_le_conn_complete(struct bthost *bthost, const void *data, uint8_t len) { @@ -822,6 +872,14 @@ static void process_evt(struct bthost *bthost, const void *data, uint16_t len) evt_encrypt_change(bthost, param, hdr->plen); break; + case BT_HCI_EVT_IO_CAPABILITY_RESPONSE: + evt_io_cap_response(bthost, param, hdr->plen); + break; + + case BT_HCI_EVT_IO_CAPABILITY_REQUEST: + evt_io_cap_request(bthost, param, hdr->plen); + break; + case BT_HCI_EVT_LE_META_EVENT: evt_le_meta_event(bthost, param, hdr->plen); break; -- 2.47.3