You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by na...@apache.org on 2019/06/18 12:55:30 UTC

[mynewt-nimble] 01/02: apps/bttester: Handle peripheral privacy

This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 39413cab73db0b0c88d91444eb455732dc1167e5
Author: MichaƂ Narajowski <mi...@codecoup.pl>
AuthorDate: Tue Jun 18 11:44:52 2019 +0200

    apps/bttester: Handle peripheral privacy
    
    Bluetooth Core Spec v5.1 | Section 10.7.1
    `If a privacy-enabled Peripheral, that has a stored bond,
    receives a resolvable private address, the Host may resolve
    the resolvable private address [...]
    If the resolution is successful, the Host may accept the connection.
    If the resolution procedure fails, then the Host shall disconnect
    with the error code "Authentication failure" [...]`
    
    This allows passing GAP/PRIV/CONN/BI-01-C.
---
 apps/bttester/src/gap.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index 2365804..719971d 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -616,6 +616,30 @@ static void conn_param_update_master(u16_t conn_handle)
 }
 #endif
 
+/* Bluetooth Core Spec v5.1 | Section 10.7.1
+ * If a privacy-enabled Peripheral, that has a stored bond,
+ * receives a resolvable private address, the Host may resolve
+ * the resolvable private address [...]
+ * If the resolution is successful, the Host may accept the connection.
+ * If the resolution procedure fails, then the Host shall disconnect
+ * with the error code "Authentication failure" [...]
+ */
+static void periph_privacy(struct ble_gap_conn_desc desc)
+{
+#if !MYNEWT_VAL(BTTESTER_PRIVACY_MODE)
+	return;
+#endif
+	int count;
+
+	SYS_LOG_DBG("");
+
+	ble_store_util_count(BLE_STORE_OBJ_TYPE_PEER_SEC, &count);
+	if (count > 0 && BLE_ADDR_IS_RPA(&desc.peer_id_addr)) {
+		SYS_LOG_DBG("Authentication failure, disconnecting");
+		ble_gap_terminate(desc.conn_handle, BLE_ERR_AUTH_FAIL);
+	}
+}
+
 static void le_connected(u16_t conn_handle, int status)
 {
 	struct ble_gap_conn_desc desc;
@@ -653,6 +677,8 @@ static void le_connected(u16_t conn_handle, int status)
 
 	tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_CONNECTED,
 		    CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
+
+	periph_privacy(desc);
 }
 
 static void le_disconnected(struct ble_gap_conn_desc *conn, int reason)