From 4fe7df6972530285f4bd96fffb11ae0ecfd3cd38 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 22 Sep 2014 21:07:13 +0300 Subject: [PATCH] emulator/bthost: Add API to enable SC support --- emulator/bthost.c | 29 +++++++++++++++++++++++++++-- emulator/bthost.h | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index 2022e6b5c..4390082af 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -213,6 +213,7 @@ struct bthost { bool reject_user_confirm; void *smp_data; bool conn_init; + bool sc; }; struct bthost *bthost_create(void) @@ -2184,7 +2185,12 @@ void bthost_request_auth(struct bthost *bthost, uint16_t handle) cp.handle = cpu_to_le16(handle); send_command(bthost, BT_HCI_CMD_AUTH_REQUESTED, &cp, sizeof(cp)); } else { - smp_pair(conn->smp_data, bthost->io_capability, bthost->auth_req); + uint8_t auth_req = bthost->auth_req; + + if (bthost->sc) + auth_req |= 0x08; + + smp_pair(conn->smp_data, bthost->io_capability, auth_req); } } @@ -2217,6 +2223,20 @@ void bthost_add_l2cap_server(struct bthost *bthost, uint16_t psm, bthost->new_l2cap_conn_data = data; } +void bthost_set_sc_support(struct bthost *bthost, bool enable) +{ + struct bt_hci_cmd_write_secure_conn_support cmd; + + bthost->sc = enable; + + if (!lmp_bredr_capable(bthost)) + return; + + cmd.support = enable; + send_command(bthost, BT_HCI_CMD_WRITE_SECURE_CONN_SUPPORT, + &cmd, sizeof(cmd)); +} + void bthost_set_pin_code(struct bthost *bthost, const uint8_t *pin, uint8_t pin_len) { @@ -2241,7 +2261,12 @@ void bthost_set_auth_req(struct bthost *bthost, uint8_t auth_req) uint8_t bthost_get_auth_req(struct bthost *bthost) { - return bthost->auth_req; + uint8_t auth_req = bthost->auth_req; + + if (bthost->sc) + auth_req |= 0x08; + + return auth_req; } void bthost_set_reject_user_confirm(struct bthost *bthost, bool reject) diff --git a/emulator/bthost.h b/emulator/bthost.h index c0fa41041..6295c1380 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -91,6 +91,8 @@ typedef void (*bthost_l2cap_connect_cb) (uint16_t handle, uint16_t cid, void bthost_add_l2cap_server(struct bthost *bthost, uint16_t psm, bthost_l2cap_connect_cb func, void *user_data); +void bthost_set_sc_support(struct bthost *bthost, bool enable); + void bthost_set_pin_code(struct bthost *bthost, const uint8_t *pin, uint8_t pin_len); void bthost_set_io_capability(struct bthost *bthost, uint8_t io_capability); -- 2.47.3