You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/03/03 13:52:41 UTC

[mynewt-nimble] branch master updated: babblesim: Add command line arg to specify bdaddr

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 811d2a5  babblesim: Add command line arg to specify bdaddr
811d2a5 is described below

commit 811d2a55d1e902b05d6c3c94e35567818a5d8d04
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Feb 21 16:38:21 2022 +0100

    babblesim: Add command line arg to specify bdaddr
    
    This allows to set public bdaddr using -A or --bdaddr command line
    option. Accepted formats are both XX:XX:XX:XX:XX:XX and 0xXXXXXXXXXXXX.
---
 babblesim/core/src/argparse.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/babblesim/core/src/argparse.c b/babblesim/core/src/argparse.c
index 68f13de..c1b6cda 100644
--- a/babblesim/core/src/argparse.c
+++ b/babblesim/core/src/argparse.c
@@ -15,6 +15,7 @@
 #include "bs_dynargs.h"
 #include "bs_cmd_line_typical.h"
 #include "NRF_HWLowL.h"
+#include "controller/ble_ll.h"
 
 static bs_args_struct_t *args_struct;
 static struct nrf52_bsim_args_t arg;
@@ -36,6 +37,28 @@ static void cmd_nosim_found(char *argv, int offset)
 	hwll_set_nosim(true);
 }
 
+static void cmd_bdaddr_found(char *argv, int offset)
+{
+    union {
+        uint64_t u64;
+        uint8_t u8[8];
+    } bdaddr;
+    char *endptr;
+
+    if (sscanf(&argv[offset], "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
+               &bdaddr.u8[5], &bdaddr.u8[4], &bdaddr.u8[3], &bdaddr.u8[2],
+               &bdaddr.u8[1], &bdaddr.u8[0]) < 6) {
+        bdaddr.u64 = strtoull(&argv[offset], &endptr, 0);
+        if (*endptr) {
+            return;
+        }
+
+        bdaddr.u64 = htole64(bdaddr.u64);
+    }
+
+    ble_ll_set_public_addr(bdaddr.u8);
+}
+
 static void print_no_sim_warning(void)
 {
 	bs_trace_warning("Neither simulation id or the device number "
@@ -70,6 +93,9 @@ void nrfbsim_register_args(void)
 		 * destination, callback,
 		 * description
 		 */
+		{ false, false , false,
+		  "A", "bdaddr", 's',
+		  NULL, cmd_bdaddr_found, "Device public address"},
 		{false, false, true,
 		"nosim", "", 'b',
 		(void *)&nosim, cmd_nosim_found,