Skip to content

Commit

Permalink
feat(bluetooth): Initial nRF52 BSIM based test support.
Browse files Browse the repository at this point in the history
Co-authored-by: Cem Aksoylar <[email protected]>
petejohanson and caksoylar committed Dec 3, 2023
1 parent da15564 commit 693530c
Showing 34 changed files with 1,054 additions and 1 deletion.
78 changes: 78 additions & 0 deletions .github/workflows/ble-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: BLE Tests

on:
push:
paths:
- ".github/workflows/ble-test.yml"
- "app/tests/ble/**"
- "app/src/**"
- "app/run-ble-test.sh"
pull_request:
paths:
- ".github/workflows/ble-test.yml"
- "app/tests/ble/**"
- "app/src/**"
- "app/run-ble-test.sh"

jobs:
collect-tests:
outputs:
test-dirs: ${{ steps.test-dirs.outputs.test-dirs }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Find test directories
id: test-dirs
run: |
cd app/tests/ble
export TESTS=$(ls -d * | grep -v central | jq -R -s -c 'split("\n")[:-1]')
echo "::set-output name=test-dirs::${TESTS}"
run-tests:
needs: collect-tests
strategy:
matrix:
test: ${{ fromJSON(needs.collect-tests.outputs.test-dirs) }}
runs-on: ubuntu-latest
container:
image: docker.io/zmkfirmware/zmk-build-arm:3.2
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache west modules
uses: actions/[email protected]
env:
cache-name: cache-zephyr-modules
with:
path: |
modules/
tools/
zephyr/
bootloader/
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('app/west.yml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
timeout-minutes: 2
continue-on-error: true
- name: Initialize workspace (west init)
run: west init -l app
- name: Enable babblesim group filter
run: west config manifest.group-filter -- +babblesim
- name: Update modules (west update)
run: west update
- name: Export Zephyr CMake package (west zephyr-export)
run: west zephyr-export
- name: Build BabbleSim components
working-directory: tools/bsim
run: make everything
- name: Test ${{ matrix.test }}
working-directory: app
run: BSIM_COMPONENTS_PATH="${GITHUB_WORKSPACE}/tools/bsim/components/" BSIM_OUT_PATH="${GITHUB_WORKSPACE}/tools/bsim/" ./run-ble-test.sh tests/ble/${{ matrix.test }}
- name: Archive artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: "log-files"
path: app/build/**/*.log
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ jobs:
id: test-dirs
run: |
cd app/tests/
export TESTS=$(ls -d * | jq -R -s -c 'split("\n")[:-1]')
export TESTS=$(ls -d * | grep -v ble | jq -R -s -c 'split("\n")[:-1]')
echo "::set-output name=test-dirs::${TESTS}"
run-tests:
needs: collect-tests
10 changes: 10 additions & 0 deletions app/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

/ {
chosen {
zephyr,console = &uart0;
zmk,kscan = &kscan;
};

@@ -15,4 +16,13 @@
columns = <2>;
exit-after;
};

uart0: uart {
status = "okay";
compatible = "zephyr,native-posix-uart";
/* Dummy current-speed entry to comply with serial
* DTS binding
*/
current-speed = <0>;
};
};
4 changes: 4 additions & 0 deletions app/boards/nrf52_bsim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_ZMK_BLE=y
CONFIG_LOG=y
CONFIG_LOG_BACKEND_SHOW_COLOR=n
CONFIG_ZMK_LOG_LEVEL_DBG=y
17 changes: 17 additions & 0 deletions app/boards/nrf52_bsim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h>

/ {
chosen {
zmk,kscan = &kscan;
};

kscan: kscan {
compatible = "zmk,kscan-mock";
label = "KSCAN_MOCK";

rows = <2>;
columns = <2>;
};
};
101 changes: 101 additions & 0 deletions app/run-ble-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# Copyright (c) 2023 The ZMK Contributors
# SPDX-License-Identifier: MIT

if [ -z "$1" ]; then
echo "Usage: ./run-ble-test.sh <path to testcase>"
exit 1
fi

path=$1
if [ "$path" = "all" ]; then
path="tests"
fi

if [ -z "${BSIM_OUT_PATH}" ]; then
echo "BSIM_OUT_PATH needs to be set before running this script."
exit 1
fi

if [ -z "$BLE_TESTS_NO_CENTRAL_BUILD" ]; then
if ! [ -e build/tests/ble/central ]; then
west build -d build/tests/ble/central -b nrf52_bsim tests/ble/central > /dev/null 2>&1
else
west build -d build/tests/ble/central
fi

cp build/tests/ble/central/zephyr/zephyr.exe "${BSIM_OUT_PATH}/bin/ble_test_central.exe"

if ! [ -e build/tests/ble/private_central ]; then
west build -d build/tests/ble/private_central -b nrf52_bsim tests/ble/central -- -DCONFIG_BT_PRIVACY=y -DCONFIG_BT_SCAN_WITH_IDENTITY=n > /dev/null 2>&1
else
west build -d build/tests/ble/private_central
fi

cp build/tests/ble/private_central/zephyr/zephyr.exe "${BSIM_OUT_PATH}/bin/ble_test_private_central.exe"
fi

testcases=$(find $path -name nrf52_bsim.keymap -exec dirname \{\} \;)
num_cases=$(echo "$testcases" | wc -l)
if [ $num_cases -gt 1 ] || [ "$testcases" != "${path%%/}" ]; then
echo "$testcases"
echo "" > ./build/tests/pass-fail.log
echo "$testcases" | BLE_TESTS_QUIET_OUTPUT=y BLE_TESTS_NO_CENTRAL_BUILD=y xargs -L 1 -P ${J:-4} ./run-ble-test.sh
err=$?
sort -k2 ./build/tests/pass-fail.log
exit $err
fi

testcase="$path"
echo "Running $testcase:"

west build -d build/$testcase -b nrf52_bsim -- -DZMK_CONFIG="$(pwd)/$testcase" > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo "FAILED: $testcase did not build" | tee -a ./build/tests/pass-fail.log
exit 1
fi

if [ -n "${BLE_TESTS_QUIET_OUTPUT}" ]; then
output_dev="/dev/null"
else
output_dev="/dev/stdout"
fi

exe_name=${testcase//\//_}

start_dir=$(pwd)
cp build/$testcase/zephyr/zmk.exe "${BSIM_OUT_PATH}/bin/${exe_name}"
pushd "${BSIM_OUT_PATH}/bin" > /dev/null 2>&1
if [ -e "${start_dir}/build/$testcase/output.log" ]; then
rm "${start_dir}/build/$testcase/output.log"
fi

central_counts=$(wc -l ${start_dir}/${testcase}/centrals.txt | cut -d' ' -f1)
./${exe_name} -d=0 -s=${exe_name} | tee -a "${start_dir}/build/$testcase/output.log" > "${output_dev}" &
./bs_device_handbrake -s=${exe_name} -d=1 -r=10 > "${output_dev}" &

cat "${start_dir}/${testcase}/centrals.txt" |
while IFS= read -r line
do
${line} -s=${exe_name} | tee -a "${start_dir}/build/$testcase/output.log" > "${output_dev}" &
done

./bs_2G4_phy_v1 -s=${exe_name} -D=$(( 2 + central_counts )) -sim_length=50e6 > "${output_dev}" 2>&1

popd > /dev/null 2>&1

cat build/$testcase/output.log | sed -E -n -f $testcase/events.patterns > build/$testcase/filtered_output.log

diff -auZ $testcase/snapshot.log build/$testcase/filtered_output.log
if [ $? -gt 0 ]; then
if [ -f $testcase/pending ]; then
echo "PENDING: $testcase" | tee -a ./build/tests/pass-fail.log
exit 0
fi
echo "FAILED: $testcase" | tee -a ./build/tests/pass-fail.log
exit 1
fi

echo "PASS: $testcase" | tee -a ./build/tests/pass-fail.log
exit 0
10 changes: 10 additions & 0 deletions app/tests/ble/central/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ble_test_central)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

# zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
9 changes: 9 additions & 0 deletions app/tests/ble/central/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONFIG_BT=y
CONFIG_LOG=y
CONFIG_BOOT_BANNER=n
CONFIG_BT_LOG_LEVEL_WRN=y
CONFIG_LOG_BACKEND_SHOW_COLOR=n
CONFIG_BT_CENTRAL=y
CONFIG_BT_SMP=y
CONFIG_BT_SCAN_WITH_IDENTITY=y
CONFIG_BT_GATT_CLIENT=y
369 changes: 369 additions & 0 deletions app/tests/ble/central/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,369 @@
/* main.c - Application main entry point */

/*
* Copyright (c) 2015-2016 Intel Corporation
* Copyright (c) 2023 The ZMK Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/types.h>
#include <stddef.h>
#include <errno.h>
#include <zephyr/kernel.h>

#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(ble_central, 4);

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/sys/byteorder.h>

#ifdef CONFIG_ARCH_POSIX

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

#include "cmdline.h"
#include "soc.h"

static bool disconnect_and_reconnect = false;
static bool clear_bond_on_disconnect = false;
static bool halt_after_bonding = false;
static int32_t wait_on_start = 0;

static void ble_central_native_posix_options(void) {
static struct args_struct_t options[] = {
{.is_switch = true,
.option = "disconnect_and_reconnect",
.type = 'b',
.dest = (void *)&disconnect_and_reconnect,
.descript = "Disconnect and reconnect after the initial connection"},
{.is_switch = true,
.option = "halt_after_bonding",
.type = 'b',
.dest = (void *)&halt_after_bonding,
.descript = "Halt any further logic after bonding the first time"},
{.is_switch = true,
.option = "clear_bond_on_disconnect",
.type = 'b',
.dest = (void *)&clear_bond_on_disconnect,
.descript = "Clear bonds on disconnect and reconnect"},
{.option = "wait_on_start",
.name = "milliseconds",
.type = 'u',
.dest = (void *)&wait_on_start,
.descript = "Time in milliseconds to wait before starting the test process"},
ARG_TABLE_ENDMARKER};

native_add_command_line_opts(options);
}

NATIVE_TASK(ble_central_native_posix_options, PRE_BOOT_1, 1);

#endif

static void start_scan(void);

static struct bt_conn *default_conn;

static struct bt_uuid_16 uuid = BT_UUID_INIT_16(0);
static struct bt_gatt_discover_params discover_params;
static struct bt_gatt_subscribe_params subscribe_params;

static uint8_t notify_func(struct bt_conn *conn, struct bt_gatt_subscribe_params *params,
const void *data, uint16_t length) {
if (!data) {
LOG_DBG("[UNSUBSCRIBED]");
params->value_handle = 0U;
return BT_GATT_ITER_STOP;
}

LOG_HEXDUMP_DBG(data, length, "payload");

return BT_GATT_ITER_CONTINUE;
}

static uint8_t discover_func(struct bt_conn *conn, const struct bt_gatt_attr *attr,
struct bt_gatt_discover_params *params) {
int err;

if (!attr) {
LOG_DBG("[Discover complete]");
(void)memset(params, 0, sizeof(*params));
return BT_GATT_ITER_STOP;
}

LOG_DBG("[ATTRIBUTE] handle %u", attr->handle);

if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_HIDS)) {
memcpy(&uuid, BT_UUID_HIDS_REPORT, sizeof(uuid));
discover_params.uuid = &uuid.uuid;
discover_params.start_handle = attr->handle + 1;
discover_params.type = BT_GATT_DISCOVER_CHARACTERISTIC;

err = bt_gatt_discover(conn, &discover_params);
if (err) {
LOG_DBG("[Discover failed] (err %d)", err);
}
} else if (!bt_uuid_cmp(discover_params.uuid, BT_UUID_HIDS_REPORT)) {
memcpy(&uuid, BT_UUID_GATT_CCC, sizeof(uuid));
discover_params.uuid = &uuid.uuid;
discover_params.start_handle = attr->handle + 2;
discover_params.type = BT_GATT_DISCOVER_DESCRIPTOR;
subscribe_params.value_handle = bt_gatt_attr_value_handle(attr);

err = bt_gatt_discover(conn, &discover_params);
if (err) {
LOG_DBG("[Discover failed] (err %d)", err);
}
} else {
subscribe_params.notify = notify_func;
subscribe_params.value = BT_GATT_CCC_NOTIFY;
subscribe_params.ccc_handle = attr->handle;

err = bt_gatt_subscribe(conn, &subscribe_params);
if (err && err != -EALREADY) {
LOG_DBG("[Subscribe failed] (err %d)", err);
} else {
LOG_DBG("[SUBSCRIBED]");
}

return BT_GATT_ITER_STOP;
}

return BT_GATT_ITER_STOP;
}

static void reconnect(const bt_addr_le_t *addr) {
struct bt_le_conn_param *param;
int err = bt_le_scan_stop();
if (err < 0) {
LOG_DBG("Stop LE scan failed (err %d)", err);
}

param = BT_LE_CONN_PARAM_DEFAULT;
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &default_conn);
if (err < 0) {
LOG_DBG("Create conn failed (err %d)", err);
start_scan();
}
}

static bool eir_found(struct bt_data *data, void *user_data) {
bt_addr_le_t *addr = user_data;
int i;

LOG_DBG("[AD]: %u data_len %u", data->type, data->data_len);

switch (data->type) {
case BT_DATA_UUID16_SOME:
case BT_DATA_UUID16_ALL:
if (data->data_len % sizeof(uint16_t) != 0U) {
LOG_DBG("[AD malformed]");
return true;
}

for (i = 0; i < data->data_len; i += sizeof(uint16_t)) {
struct bt_le_conn_param *param;
struct bt_uuid *uuid;
uint16_t u16;
int err;

memcpy(&u16, &data->data[i], sizeof(u16));
uuid = BT_UUID_DECLARE_16(sys_le16_to_cpu(u16));
if (bt_uuid_cmp(uuid, BT_UUID_HIDS)) {
continue;
}

err = bt_le_scan_stop();
if (err) {
LOG_DBG("[Stop LE scan failed] (err %d)", err);
continue;
}

param = BT_LE_CONN_PARAM_DEFAULT;
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &default_conn);
if (err) {
LOG_DBG("[Create conn failed] (err %d)", err);
start_scan();
}

return false;
}
}

return true;
}

static void device_found(const bt_addr_le_t *addr, int8_t rssi, uint8_t type,
struct net_buf_simple *ad) {
char dev[BT_ADDR_LE_STR_LEN];

bt_addr_le_to_str(addr, dev, sizeof(dev));
LOG_DBG("[DEVICE]: %s, AD evt type %u, AD data len %u, RSSI %i", dev, type, ad->len, rssi);

/* We're only interested in connectable events */
if (type == BT_GAP_ADV_TYPE_ADV_IND) {
bt_data_parse(ad, eir_found, (void *)addr);
} else if (type == BT_GAP_ADV_TYPE_ADV_DIRECT_IND) {
reconnect(addr);
}
}

static void start_scan(void) {
int err;

/* Use active scanning and disable duplicate filtering to handle any
* devices that might update their advertising data at runtime. */
struct bt_le_scan_param scan_param = {
.type = BT_LE_SCAN_TYPE_ACTIVE,
.options = BT_LE_SCAN_OPT_NONE,
.interval = BT_GAP_SCAN_FAST_INTERVAL,
.window = BT_GAP_SCAN_FAST_WINDOW,
};

err = bt_le_scan_start(&scan_param, device_found);
if (err) {
LOG_DBG("[Scanning failed to start] (err %d)", err);
return;
}

LOG_DBG("[Scanning successfully started]");
}

static void discover_conn(struct bt_conn *conn) {
int err;

LOG_DBG("[Discovery started for conn]");
memcpy(&uuid, BT_UUID_HIDS, sizeof(uuid));
discover_params.uuid = &uuid.uuid;
discover_params.func = discover_func;
discover_params.start_handle = BT_ATT_FIRST_ATTRIBUTE_HANDLE;
discover_params.end_handle = BT_ATT_LAST_ATTRIBUTE_HANDLE;
discover_params.type = BT_GATT_DISCOVER_PRIMARY;

err = bt_gatt_discover(default_conn, &discover_params);
if (err) {
LOG_DBG("[Discover failed] (err %d)", err);
return;
}
}

static void connected(struct bt_conn *conn, uint8_t conn_err) {
char addr[BT_ADDR_LE_STR_LEN];

bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

if (conn_err) {
LOG_DBG("[Failed to connect to %s] (%u)", addr, conn_err);

bt_conn_unref(default_conn);
default_conn = NULL;

start_scan();
return;
}

LOG_DBG("[Connected]: %s", addr);

if (conn == default_conn) {
if (bt_conn_get_security(conn) >= BT_SECURITY_L2) {
discover_conn(conn);
} else {
LOG_DBG("[Setting the security for the connection]");
bt_conn_set_security(conn, BT_SECURITY_L2);
}
}
}

static bool first_connect = true;
static void pairing_complete(struct bt_conn *conn, bool bonded) { LOG_DBG("Pairing complete"); }

static void do_disconnect_of_active(struct k_work *work) {
bt_conn_disconnect(default_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
if (clear_bond_on_disconnect) {
bt_unpair(BT_ID_DEFAULT, bt_conn_get_dst(default_conn));
}
}

static K_WORK_DELAYABLE_DEFINE(disconnect_work, do_disconnect_of_active);

static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err) {
if (err > BT_SECURITY_ERR_SUCCESS) {
LOG_DBG("[Security Change Failed]");
exit(1);
}

if (halt_after_bonding) {
exit(1);
}

bool do_disconnect = first_connect && disconnect_and_reconnect;
first_connect = false;
if (do_disconnect) {
k_work_reschedule(&disconnect_work, K_MSEC(500));
} else {
discover_conn(conn);
}
}

static void disconnected(struct bt_conn *conn, uint8_t reason) {
char addr[BT_ADDR_LE_STR_LEN];

bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

LOG_DBG("[Disconnected]: %s (reason 0x%02x)", addr, reason);

if (default_conn != conn) {
return;
}

bt_conn_unref(default_conn);
default_conn = NULL;

if (!halt_after_bonding) {
start_scan();
}
}

BT_CONN_CB_DEFINE(conn_callbacks) = {
.connected = connected,
.disconnected = disconnected,
.security_changed = security_changed,
};

struct bt_conn_auth_info_cb auth_info_cb = {
.pairing_complete = pairing_complete,
};

void main(void) {
int err;

if (wait_on_start > 0) {
k_sleep(K_MSEC(wait_on_start));
}

err = bt_conn_auth_info_cb_register(&auth_info_cb);

err = bt_enable(NULL);

if (err) {
LOG_DBG("[Bluetooth init failed] (err %d)", err);
return;
}

LOG_DBG("[Bluetooth initialized]");

start_scan();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./ble_test_central.exe -d=2 -halt_after_bonding
./ble_test_central.exe -d=3 -wait_on_start=1300
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s/^d_02: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 0 /p
s/^d_03: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 1 /p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h>

&kscan {
events =
<ZMK_MOCK_PRESS(1,1,5000)
ZMK_MOCK_RELEASE(1,1,200)
ZMK_MOCK_PRESS(0,0,10)
ZMK_MOCK_RELEASE(0,0,2000)>;
};

/ {
keymap {
compatible = "zmk,keymap";
label = "Default keymap";

default_layer {
bindings = <
&kp A &kp B
&bt BT_SEL 0 &bt BT_CLR>;
};
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
profile 0 <wrn> bt_id: No static addresses stored in controller
profile 0 <dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
profile 0 <dbg> ble_central: start_scan: [Scanning successfully started]
profile 0 <dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
profile 0 <dbg> ble_central: eir_found: [AD]: 9 data_len 0
profile 0 <dbg> ble_central: eir_found: [AD]: 25 data_len 2
profile 0 <dbg> ble_central: eir_found: [AD]: 1 data_len 1
profile 0 <dbg> ble_central: eir_found: [AD]: 2 data_len 4
profile 0 <dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
profile 0 <dbg> ble_central: connected: [Setting the security for the connection]
profile 0 <dbg> ble_central: pairing_complete: Pairing complete
profile 1 <wrn> bt_id: No static addresses stored in controller
profile 1 <dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
profile 1 <dbg> ble_central: start_scan: [Scanning successfully started]
profile 1 <dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
profile 1 <dbg> ble_central: eir_found: [AD]: 9 data_len 0
profile 1 <dbg> ble_central: eir_found: [AD]: 25 data_len 2
profile 1 <dbg> ble_central: eir_found: [AD]: 1 data_len 1
profile 1 <dbg> ble_central: eir_found: [AD]: 2 data_len 4
profile 1 <dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
profile 1 <dbg> ble_central: connected: [Setting the security for the connection]
profile 1 <dbg> ble_central: pairing_complete: Pairing complete
profile 1 <dbg> ble_central: discover_conn: [Discovery started for conn]
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 23
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 28
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 30
profile 1 <dbg> ble_central: discover_func: [SUBSCRIBED]
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 04 00 00 00 00 00 |........
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 00 00 00 00 00 00 |........
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 00 00 00 00 00 00 |........
2 changes: 2 additions & 0 deletions app/tests/ble/profiles/bond-to-cleared-profile/centrals.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./ble_test_central.exe -d=2 -halt_after_bonding
./ble_test_central.exe -d=3 -wait_on_start=1300
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s/^d_02: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 0 /p
s/^d_03: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 1 /p
25 changes: 25 additions & 0 deletions app/tests/ble/profiles/bond-to-cleared-profile/nrf52_bsim.keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h>

&kscan {
events =
<ZMK_MOCK_PRESS(1,1,1000)
ZMK_MOCK_RELEASE(1,1,2000)
ZMK_MOCK_PRESS(0,0,100)
ZMK_MOCK_RELEASE(0,0,1000)>;
};

/ {
keymap {
compatible = "zmk,keymap";
label = "Default keymap";

default_layer {
bindings = <
&kp A &kp B
&bt BT_SEL 0 &bt BT_CLR>;
};
};
};
33 changes: 33 additions & 0 deletions app/tests/ble/profiles/bond-to-cleared-profile/snapshot.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
profile 0 <wrn> bt_id: No static addresses stored in controller
profile 0 <dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
profile 0 <dbg> ble_central: start_scan: [Scanning successfully started]
profile 0 <dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
profile 0 <dbg> ble_central: eir_found: [AD]: 9 data_len 0
profile 0 <dbg> ble_central: eir_found: [AD]: 25 data_len 2
profile 0 <dbg> ble_central: eir_found: [AD]: 1 data_len 1
profile 0 <dbg> ble_central: eir_found: [AD]: 2 data_len 4
profile 0 <dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
profile 0 <dbg> ble_central: connected: [Setting the security for the connection]
profile 0 <dbg> ble_central: pairing_complete: Pairing complete
profile 1 <wrn> bt_id: No static addresses stored in controller
profile 1 <dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
profile 1 <dbg> ble_central: start_scan: [Scanning successfully started]
profile 1 <dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
profile 1 <dbg> ble_central: eir_found: [AD]: 9 data_len 0
profile 1 <dbg> ble_central: eir_found: [AD]: 25 data_len 2
profile 1 <dbg> ble_central: eir_found: [AD]: 1 data_len 1
profile 1 <dbg> ble_central: eir_found: [AD]: 2 data_len 4
profile 1 <dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
profile 1 <dbg> ble_central: connected: [Setting the security for the connection]
profile 1 <dbg> ble_central: pairing_complete: Pairing complete
profile 1 <dbg> ble_central: discover_conn: [Discovery started for conn]
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 23
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 28
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 30
profile 1 <dbg> ble_central: discover_func: [SUBSCRIBED]
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 04 00 00 00 00 00 |........
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 00 00 00 00 00 00 |........
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 00 00 00 00 00 00 |........
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./ble_test_central.exe -d=2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s/^d_02: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}//p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h>

&kscan {
events =
<ZMK_MOCK_PRESS(0,0,10000)
ZMK_MOCK_RELEASE(0,0,2000)
ZMK_MOCK_PRESS(0,1,100)
ZMK_MOCK_RELEASE(0,1,1000)>;
};

/ {
keymap {
compatible = "zmk,keymap";
label = "Default keymap";

default_layer {
bindings = <
&kp A &kp B
&bt BT_SEL 0 &bt BT_SEL 1>;
};
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<wrn> bt_id: No static addresses stored in controller
<dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
<dbg> ble_central: start_scan: [Scanning successfully started]
<dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
<dbg> ble_central: eir_found: [AD]: 9 data_len 0
<dbg> ble_central: eir_found: [AD]: 25 data_len 2
<dbg> ble_central: eir_found: [AD]: 1 data_len 1
<dbg> ble_central: eir_found: [AD]: 2 data_len 4
<dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
<dbg> ble_central: connected: [Setting the security for the connection]
<dbg> ble_central: pairing_complete: Pairing complete
<dbg> ble_central: discover_conn: [Discovery started for conn]
<dbg> ble_central: discover_func: [ATTRIBUTE] handle 23
<dbg> ble_central: discover_func: [ATTRIBUTE] handle 28
<dbg> ble_central: discover_func: [ATTRIBUTE] handle 30
<dbg> ble_central: discover_func: [SUBSCRIBED]
<dbg> ble_central: notify_func: payload
00 00 04 00 00 00 00 00 |........
<dbg> ble_central: notify_func: payload
00 00 00 00 00 00 00 00 |........
<dbg> ble_central: notify_func: payload
00 00 05 00 00 00 00 00 |........
<dbg> ble_central: notify_func: payload
00 00 00 00 00 00 00 00 |........
<dbg> ble_central: notify_func: payload
00 00 00 00 00 00 00 00 |........
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./ble_test_central.exe -d=2 -halt_after_bonding
./ble_test_central.exe -d=3 -wait_on_start=1300
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s/^d_02: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 0 /p
s/^d_03: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 1 /p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h>

&kscan {
events =
<ZMK_MOCK_PRESS(0,0,10000)
ZMK_MOCK_RELEASE(0,0,2000)
ZMK_MOCK_PRESS(0,1,100)
ZMK_MOCK_RELEASE(0,1,1000)>;
};

/ {
keymap {
compatible = "zmk,keymap";
label = "Default keymap";

default_layer {
bindings = <
&kp A &kp B
&bt BT_SEL 0 &bt BT_SEL 1>;
};
};
};
23 changes: 23 additions & 0 deletions app/tests/ble/profiles/dont-bond-to-taken-profile/snapshot.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
profile 0 <wrn> bt_id: No static addresses stored in controller
profile 0 <dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
profile 0 <dbg> ble_central: start_scan: [Scanning successfully started]
profile 0 <dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
profile 0 <dbg> ble_central: eir_found: [AD]: 9 data_len 0
profile 0 <dbg> ble_central: eir_found: [AD]: 25 data_len 2
profile 0 <dbg> ble_central: eir_found: [AD]: 1 data_len 1
profile 0 <dbg> ble_central: eir_found: [AD]: 2 data_len 4
profile 0 <dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
profile 0 <dbg> ble_central: connected: [Setting the security for the connection]
profile 0 <dbg> ble_central: pairing_complete: Pairing complete
profile 1 <wrn> bt_id: No static addresses stored in controller
profile 1 <dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
profile 1 <dbg> ble_central: start_scan: [Scanning successfully started]
profile 1 <dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
profile 1 <dbg> ble_central: eir_found: [AD]: 9 data_len 0
profile 1 <dbg> ble_central: eir_found: [AD]: 25 data_len 2
profile 1 <dbg> ble_central: eir_found: [AD]: 1 data_len 1
profile 1 <dbg> ble_central: eir_found: [AD]: 2 data_len 4
profile 1 <dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
profile 1 <dbg> ble_central: connected: [Setting the security for the connection]
profile 1 <err> bt_smp: reason 0x8
profile 1 <dbg> ble_central: security_changed: [Security Change Failed]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./ble_test_central.exe -d=2
./ble_test_central.exe -d=3 -wait_on_start=1300
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s/^d_02: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 0 /p
s/^d_03: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}/profile 1 /p
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h>

&kscan {
events =
<ZMK_MOCK_PRESS(0,0,5000)
ZMK_MOCK_RELEASE(0,0,200)
ZMK_MOCK_PRESS(1,1,10)
ZMK_MOCK_RELEASE(1,1,2000)
ZMK_MOCK_PRESS(0,1,1000)
ZMK_MOCK_RELEASE(0,1,1000)>;
};

/ {
keymap {
compatible = "zmk,keymap";
label = "Default keymap";

default_layer {
bindings = <
&kp A &kp B
&bt BT_SEL 0 &bt BT_SEL 1>;
};
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
profile 0 <wrn> bt_id: No static addresses stored in controller
profile 0 <dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
profile 0 <dbg> ble_central: start_scan: [Scanning successfully started]
profile 0 <dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
profile 0 <dbg> ble_central: eir_found: [AD]: 9 data_len 0
profile 0 <dbg> ble_central: eir_found: [AD]: 25 data_len 2
profile 0 <dbg> ble_central: eir_found: [AD]: 1 data_len 1
profile 0 <dbg> ble_central: eir_found: [AD]: 2 data_len 4
profile 0 <dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
profile 0 <dbg> ble_central: connected: [Setting the security for the connection]
profile 0 <dbg> ble_central: pairing_complete: Pairing complete
profile 0 <dbg> ble_central: discover_conn: [Discovery started for conn]
profile 0 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 23
profile 1 <wrn> bt_id: No static addresses stored in controller
profile 1 <dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
profile 1 <dbg> ble_central: start_scan: [Scanning successfully started]
profile 0 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 28
profile 0 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 30
profile 0 <dbg> ble_central: discover_func: [SUBSCRIBED]
profile 0 <dbg> ble_central: notify_func: payload
profile 0 00 00 04 00 00 00 00 00 |........
profile 0 <dbg> ble_central: notify_func: payload
profile 0 00 00 00 00 00 00 00 00 |........
profile 1 <dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
profile 1 <dbg> ble_central: eir_found: [AD]: 9 data_len 0
profile 1 <dbg> ble_central: eir_found: [AD]: 25 data_len 2
profile 1 <dbg> ble_central: eir_found: [AD]: 1 data_len 1
profile 1 <dbg> ble_central: eir_found: [AD]: 2 data_len 4
profile 1 <dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
profile 1 <dbg> ble_central: connected: [Setting the security for the connection]
profile 1 <dbg> ble_central: pairing_complete: Pairing complete
profile 1 <dbg> ble_central: discover_conn: [Discovery started for conn]
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 23
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 28
profile 1 <dbg> ble_central: discover_func: [ATTRIBUTE] handle 30
profile 1 <dbg> ble_central: discover_func: [SUBSCRIBED]
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 05 00 00 00 00 00 |........
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 00 00 00 00 00 00 |........
profile 1 <dbg> ble_central: notify_func: payload
profile 1 00 00 00 00 00 00 00 00 |........
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./ble_test_central.exe -d=2 -disconnect_and_reconnect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s/^d_02: @[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9] .{19}//p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <behaviors.dtsi>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/kscan_mock.h>

&kscan {
events =
<ZMK_MOCK_PRESS(0,0,10000)
ZMK_MOCK_RELEASE(0,0,2000)
ZMK_MOCK_PRESS(0,1,100)
ZMK_MOCK_RELEASE(0,1,1000)>;
};

/ {
keymap {
compatible = "zmk,keymap";
label = "Default keymap";

default_layer {
bindings = <
&kp A &kp B
&bt BT_SEL 0 &bt BT_SEL 1>;
};
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<wrn> bt_id: No static addresses stored in controller
<dbg> ble_central: _posix_zephyr_main: [Bluetooth initialized]
<dbg> ble_central: start_scan: [Scanning successfully started]
<dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
<dbg> ble_central: eir_found: [AD]: 9 data_len 0
<dbg> ble_central: eir_found: [AD]: 25 data_len 2
<dbg> ble_central: eir_found: [AD]: 1 data_len 1
<dbg> ble_central: eir_found: [AD]: 2 data_len 4
<dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
<dbg> ble_central: connected: [Setting the security for the connection]
<dbg> ble_central: pairing_complete: Pairing complete
<dbg> ble_central: disconnected: [Disconnected]: ED:3B:20:15:18:12 (random) (reason 0x16)
<dbg> ble_central: start_scan: [Scanning successfully started]
<dbg> ble_central: device_found: [DEVICE]: ED:3B:20:15:18:12 (random), AD evt type 0, AD data len 15, RSSI -59
<dbg> ble_central: eir_found: [AD]: 9 data_len 0
<dbg> ble_central: eir_found: [AD]: 25 data_len 2
<dbg> ble_central: eir_found: [AD]: 1 data_len 1
<dbg> ble_central: eir_found: [AD]: 2 data_len 4
<dbg> ble_central: connected: [Connected]: ED:3B:20:15:18:12 (random)
<dbg> ble_central: connected: [Setting the security for the connection]
<dbg> ble_central: discover_conn: [Discovery started for conn]
<dbg> ble_central: discover_func: [ATTRIBUTE] handle 23
<dbg> ble_central: discover_func: [ATTRIBUTE] handle 28
<dbg> ble_central: discover_func: [ATTRIBUTE] handle 30
<dbg> ble_central: discover_func: [SUBSCRIBED]
<dbg> ble_central: notify_func: payload
00 00 04 00 00 00 00 00 |........
<dbg> ble_central: notify_func: payload
00 00 00 00 00 00 00 00 |........
<dbg> ble_central: notify_func: payload
00 00 05 00 00 00 00 00 |........
<dbg> ble_central: notify_func: payload
00 00 00 00 00 00 00 00 |........
<dbg> ble_central: notify_func: payload
00 00 00 00 00 00 00 00 |........
91 changes: 91 additions & 0 deletions app/west.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
manifest:
defaults:
remote: upstream

remotes:
- name: zephyrproject-rtos
url-base: https://github.com/zephyrproject-rtos
- name: zmkfirmware
url-base: https://github.com/zmkfirmware
- name: upstream
url-base: https://github.com/zephyrproject-rtos
- name: babblesim
url-base: https://github.com/BabbleSim
group-filter: [-babblesim]
projects:
- name: zephyr
remote: zmkfirmware
@@ -30,5 +38,88 @@ manifest:
- edtt
- trusted-firmware-m
- sof
- name: bsim
repo-path: babblesim-manifest
revision: 908ffde6298a937c6549dbfa843a62caab26bfc5
path: tools/bsim
groups:
- babblesim
- name: babblesim_base
remote: babblesim
repo-path: base.git
path: tools/bsim/components
revision: 02838ca04c4562e68dc876196828d8121679e537
groups:
- babblesim
- name: babblesim_ext_2G4_libPhyComv1
remote: babblesim
repo-path: ext_2G4_libPhyComv1.git
path: tools/bsim/components/ext_2G4_libPhyComv1
revision: 9018113a362fa6c9e8f4b9cab9e5a8f12cc46b94
groups:
- babblesim
- name: babblesim_ext_2G4_phy_v1
remote: babblesim
repo-path: ext_2G4_phy_v1.git
path: tools/bsim/components/ext_2G4_phy_v1
revision: cf2d86e736efac4f12fad5093ed2da2c5b406156
groups:
- babblesim
- name: babblesim_ext_2G4_channel_NtNcable
remote: babblesim
repo-path: ext_2G4_channel_NtNcable.git
path: tools/bsim/components/ext_2G4_channel_NtNcable
revision: 20a38c997f507b0aa53817aab3d73a462fff7af1
groups:
- babblesim
- name: babblesim_ext_2G4_channel_multiatt
remote: babblesim
repo-path: ext_2G4_channel_multiatt.git
path: tools/bsim/components/ext_2G4_channel_multiatt
revision: e09bc2d14b1975f969ad19c6ed23eb20e5dc3d09
groups:
- babblesim
- name: babblesim_ext_2G4_modem_magic
remote: babblesim
repo-path: ext_2G4_modem_magic.git
path: tools/bsim/components/ext_2G4_modem_magic
revision: cb70771794f0bf6f262aa474848611c68ae8f1ed
groups:
- babblesim
- name: babblesim_ext_2G4_modem_BLE_simple
remote: babblesim
repo-path: ext_2G4_modem_BLE_simple.git
path: tools/bsim/components/ext_2G4_modem_BLE_simple
revision: ce975a3259fd0dd761d371b60435242d54794bad
groups:
- babblesim
- name: babblesim_ext_2G4_device_burst_interferer
remote: babblesim
repo-path: ext_2G4_device_burst_interferer.git
path: tools/bsim/components/ext_2G4_device_burst_interferer
revision: 5b5339351d6e6a2368c686c734dc8b2fc65698fc
groups:
- babblesim
- name: babblesim_ext_2G4_device_WLAN_actmod
remote: babblesim
repo-path: ext_2G4_device_WLAN_actmod.git
path: tools/bsim/components/ext_2G4_device_WLAN_actmod
revision: 9cb6d8e72695f6b785e57443f0629a18069d6ce4
groups:
- babblesim
- name: babblesim_ext_2G4_device_playback
remote: babblesim
repo-path: ext_2G4_device_playback.git
path: tools/bsim/components/ext_2G4_device_playback
revision: 85c645929cf1ce995d8537107d9dcbd12ed64036
groups:
- babblesim
- name: babblesim_ext_libCryptov1
remote: babblesim
repo-path: ext_libCryptov1.git
path: tools/bsim/components/ext_libCryptov1
revision: eed6d7038e839153e340bd333bc43541cb90ba64
groups:
- babblesim
self:
west-commands: scripts/west-commands.yml

0 comments on commit 693530c

Please sign in to comment.