Diff between 920c1ca1cce056680d6226ac986c8f0d94a6ca51 and 4fe7df6972530285f4bd96fffb11ae0ecfd3cd38

Changed Files

File Additions Deletions Status
emulator/bthost.c +27 -2 modified
emulator/bthost.h +2 -0 modified

Full Patch

diff --git a/emulator/bthost.c b/emulator/bthost.c
index 2022e6b..4390082 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 c0fa410..6295c13 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);