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/12/09 14:37:31 UTC

[mynewt-nimble] 03/03: apps/btshell: Add support for OOB Secure Connections

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 aade608f6b4e2ca43469da58b69461e485749026
Author: MichaƂ Narajowski <mi...@codecoup.pl>
AuthorDate: Tue Dec 3 11:52:33 2019 +0100

    apps/btshell: Add support for OOB Secure Connections
---
 apps/btshell/src/cmd.c  | 58 ++++++++++++++++++++++++++++++++++++++++++++++---
 apps/btshell/src/main.c | 13 +++++++++++
 2 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/apps/btshell/src/cmd.c b/apps/btshell/src/cmd.c
index 1bb174f..bcf559e 100644
--- a/apps/btshell/src/cmd.c
+++ b/apps/btshell/src/cmd.c
@@ -2493,6 +2493,31 @@ static const struct shell_cmd_help keystore_show_help = {
 
 #if NIMBLE_BLE_SM
 /*****************************************************************************
+ * $show-oob-sc                                                              *
+ *****************************************************************************/
+
+extern struct ble_sm_sc_oob_data oob_data_local;
+extern struct ble_sm_sc_oob_data oob_data_remote;
+
+static int
+cmd_show_oob_sc(int argc, char **argv)
+{
+    console_printf("Local OOB Data: r=");
+    print_bytes(oob_data_local.r, 16);
+    console_printf(" c=");
+    print_bytes(oob_data_local.c, 16);
+    console_printf("\n");
+
+    console_printf("Remote OOB Data: r=");
+    print_bytes(oob_data_remote.r, 16);
+    console_printf(" c=");
+    print_bytes(oob_data_remote.c, 16);
+    console_printf("\n");
+
+    return 0;
+}
+
+/*****************************************************************************
  * $auth-passkey                                                             *
  *****************************************************************************/
 
@@ -2563,9 +2588,29 @@ cmd_auth_passkey(int argc, char **argv)
             }
             break;
 
-       default:
-         console_printf("invalid passkey action action=%d\n", pk.action);
-         return EINVAL;
+        case BLE_SM_IOACT_OOB_SC:
+            rc = parse_arg_byte_stream_exact_length("r", oob_data_remote.r, 16);
+            if (rc != 0 && rc != ENOENT) {
+                console_printf("invalid 'r' parameter\n");
+                return rc;
+            }
+
+            rc = parse_arg_byte_stream_exact_length("c", oob_data_remote.c, 16);
+            if (rc != 0 && rc != ENOENT) {
+                console_printf("invalid 'c' parameter\n");
+                return rc;
+            }
+            pk.oob_sc_data.local = &oob_data_local;
+            if (ble_hs_cfg.sm_oob_data_flag) {
+                pk.oob_sc_data.remote = &oob_data_remote;
+            } else {
+                pk.oob_sc_data.remote = NULL;
+            }
+            break;
+
+        default:
+            console_printf("invalid passkey action action=%d\n", pk.action);
+            return EINVAL;
     }
 
     rc = ble_sm_inject_io(conn_handle, &pk);
@@ -4344,6 +4389,13 @@ static const struct shell_cmd btshell_commands[] = {
     },
 #if NIMBLE_BLE_SM
     {
+        .sc_cmd = "show-oob-sc",
+        .sc_cmd_func = cmd_show_oob_sc,
+#if MYNEWT_VAL(SHELL_CMD_HELP)
+        .help = NULL,
+#endif
+    },
+    {
         .sc_cmd = "auth-passkey",
         .sc_cmd_func = cmd_auth_passkey,
 #if MYNEWT_VAL(SHELL_CMD_HELP)
diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c
index 8abe190..26ade44 100644
--- a/apps/btshell/src/main.c
+++ b/apps/btshell/src/main.c
@@ -119,6 +119,9 @@ struct btshell_tx_data_s
 static struct btshell_tx_data_s btshell_tx_data;
 int btshell_full_disc_prev_chr_val;
 
+struct ble_sm_sc_oob_data oob_data_local;
+struct ble_sm_sc_oob_data oob_data_remote;
+
 #define XSTR(s) STR(s)
 #ifndef STR
 #define STR(s) #s
@@ -2102,6 +2105,16 @@ btshell_on_reset(int reason)
 static void
 btshell_on_sync(void)
 {
+#if MYNEWT_VAL(BLE_SM_SC)
+    int rc;
+
+    rc = ble_sm_sc_oob_generate_data(&oob_data_local);
+    if (rc) {
+        console_printf("Error: generating oob data; reason=%d\n", rc);
+        return;
+    }
+#endif
+
     console_printf("Host and controller synced\n");
 }