Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/known_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ KRKNWK-21160: Semtech interrupt pin remains high blocking the Wi-Fi scan.

**Workaround:** Clear event pin interrupt in Semtech hal after each occurrence.

KRKNWK-21514: Sidewalk option for Bluetooth LE config (``SID_OPTION_BLE_USER_CONFIG``) is not supported in the NCS
Calling the Sidewalk Kconfig option ``SID_OPTION_BLE_USER_CONFIG`` causes the application to crash.

**Affected platforms:** All platforms.

List of known issues for v1.0.1
*******************************

Expand Down
8 changes: 8 additions & 0 deletions samples/sid_end_device/include/cli/app_shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@
#define CMD_SID_SET_OPTION_LP_SET_ARG_OPTIONAL 1
#define CMD_SID_OPTION_GSI_ARG_REQUIRED 1
#define CMD_SID_OPTION_GSI_ARG_OPTIONAL 0
#define CMD_SID_OPTION_BLE_CFG_DESCRIPTION \
"set <cfg_type> [inactivity_timeout]\n" \
"Set BLE user config (SID_OPTION_BLE_USER_CONFIG).\n" \
"<cfg_type> 0=ADV, 1=CONN, 2=ADV_AND_CONN, 3=INACTIVITY_TIMEOUT.\n" \
"For cfg_type 3, <inactivity_timeout> (seconds) is required."
#define CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED 2
#define CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL 1
#define CMD_SID_LAST_STATUS_ARG_REQUIRED 1
#define CMD_SID_LAST_STATUS_ARG_OPTIONAL 0
#define CMD_SID_CONN_REQUEST_ARG_REQUIRED 2
Expand Down Expand Up @@ -271,6 +278,7 @@ int cmd_sid_option_c(const struct shell *shell, int32_t argc, const char **argv)
int cmd_sid_option_ml(const struct shell *shell, int32_t argc, const char **argv);
int cmd_sid_option_gc(const struct shell *shell, int32_t argc, const char **argv);
int cmd_sid_option_sid_id(const struct shell *shell, int32_t argc, const char **argv);
int cmd_sid_option_ble_cfg_set(const struct shell *shell, int32_t argc, const char **argv);

int cmd_sid_last_status(const struct shell *shell, int32_t argc, const char **argv);
int cmd_sid_conn_request(const struct shell *shell, int32_t argc, const char **argv);
Expand Down
68 changes: 68 additions & 0 deletions samples/sid_end_device/src/cli/app_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <sid_api.h>
#include <sid_900_cfg.h>
#include <sid_ble_config_ifc.h>
#include <sid_hal_memory_ifc.h>

#include <cli/app_shell.h>
Expand Down Expand Up @@ -79,6 +80,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
CMD_SID_SET_OPTION_GC_ARG_REQUIRED, CMD_SID_SET_OPTION_GC_ARG_OPTIONAL),
SHELL_CMD_ARG(-gsi, NULL, CMD_SID_OPTION_GSI_DESCRIPTION, cmd_sid_option_sid_id,
CMD_SID_OPTION_GSI_ARG_REQUIRED, CMD_SID_OPTION_GSI_ARG_OPTIONAL),
SHELL_CMD_ARG(-ble_cfg, NULL, CMD_SID_OPTION_BLE_CFG_DESCRIPTION,
cmd_sid_option_ble_cfg_set, CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED,
CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL),

SHELL_SUBCMD_SET_END);

Expand Down Expand Up @@ -989,6 +993,70 @@ int cmd_sid_option_gc(const struct shell *shell, int32_t argc, const char **argv
return 0;
}

#define BLE_CFG_MS_TO_ADV_INTERVAL(ms) ((uint32_t)(((ms) * 8U) / 5U))
#define BLE_CFG_MS_TO_CONN_INTERVAL(ms) ((uint16_t)(((ms) * 8U) / 5U))

int cmd_sid_option_ble_cfg_set(const struct shell *shell, int32_t argc, const char **argv)
{
CHECK_ARGUMENT_COUNT(argc, CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED,
CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL);

if (strcmp(argv[1], "set") != 0) {
shell_error(shell, "First argument must be 'set'");
return -EINVAL;
}

long cfg_type_raw = 0l;
char *end = NULL;
cfg_type_raw = strtol(argv[2], &end, 0);
if (end == argv[2] || !IN_RANGE(cfg_type_raw, SID_BLE_USER_CFG_ADV,
SID_BLE_USER_CFG_INACTIVITY_TIMEOUT)) {
shell_error(shell, "cfg_type must be 0..3 (ADV, CONN, ADV_AND_CONN, INACTIVITY_TIMEOUT)");
return -EINVAL;
}

struct sid_ble_user_config cfg = {
.adv_param = {
.type = AMA_SERVICE,
.fast_enabled = true,
.slow_enabled = true,
.fast_interval = BLE_CFG_MS_TO_ADV_INTERVAL(CONFIG_SIDEWALK_BLE_ADV_INT_FAST),
.fast_timeout = CONFIG_SIDEWALK_BLE_ADV_INT_TRANSITION * 100, /* seconds to 10ms */
.slow_interval = BLE_CFG_MS_TO_ADV_INTERVAL(CONFIG_SIDEWALK_BLE_ADV_INT_SLOW),
.slow_timeout = 0,
},
.conn_param = {
.min_conn_interval = BLE_CFG_MS_TO_CONN_INTERVAL(CONFIG_SIDEWALK_BLE_ADV_INT_SLOW),
.max_conn_interval = BLE_CFG_MS_TO_CONN_INTERVAL(CONFIG_SIDEWALK_BLE_ADV_INT_FAST),
.slave_latency = CONFIG_BT_PERIPHERAL_PREF_LATENCY,
.conn_sup_timeout = CONFIG_BT_PERIPHERAL_PREF_TIMEOUT,
},
.is_set = true,
.cfg_type = (enum sid_ble_user_config_type)cfg_type_raw,
.inactivity_timeout = 0,
};

if (cfg.cfg_type == SID_BLE_USER_CFG_INACTIVITY_TIMEOUT) {
if (argc < 4) {
shell_error(shell, "inactivity_timeout required for cfg_type 3");
return -EINVAL;
}
unsigned long timeout = strtoul(argv[3], &end, 0);
if (end == argv[3] || timeout > UINT32_MAX) {
shell_error(shell, "Invalid inactivity_timeout");
return -EINVAL;
}
cfg.inactivity_timeout = (uint32_t)timeout;
}

int err = cmd_sid_option_set(SID_OPTION_BLE_USER_CONFIG, &cfg, sizeof(cfg));
if (err) {
shell_error(shell, "event err %d", err);
}

return 0;
}

int cmd_sid_last_status(const struct shell *shell, int32_t argc, const char **argv)
{
CHECK_ARGUMENT_COUNT(argc, CMD_SID_LAST_STATUS_ARG_REQUIRED,
Expand Down
12 changes: 7 additions & 5 deletions subsys/sal/sid_pal/include/bt_app_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ int sid_ble_bt_enable(bt_ready_cb_t cb);

/**
* @brief Wrapper for @bt_disable.
* This function removes internal reference.
* If the internal reference counter shows 0, real @bt_disable is called
*
* @return int result from @bt_disable or 0 if sid_ble_bt_enable has been called more than sid_ble_bt_disable
* This function removes an internal reference.
* If the internal reference counter reaches 0, the real @bt_disable is called.
*
* @return int 0 on successful disable,
* Negative error codes as returned by @bt_disable,
* Positive number indicating the number of connections left.
*/
int sid_ble_bt_disable();

/**
* @brief BT ids used for extended advertising.
* This allows to identify connections from different extended adverticements.
* This allows to identify connections from different extended advertisements.
*/
enum sid_ble_id_values {
_BT_ID_DEFAULT = BT_ID_DEFAULT,
Expand Down
2 changes: 1 addition & 1 deletion subsys/sal/sid_pal/src/bt_app_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int sid_ble_bt_disable()
return bt_disable();
} else {
bt_enable_count--;
return 0;
return bt_enable_count;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could that cause any issue, before this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't an issue, but it might be surprised that e.g. Bluetooth still advertise as DFU device, when Sidewalk is in LoRa only mode.
Before this change there was no difference between disabling Bluetooth entirely and disabling just Sidewalk advertising. Now return value helps distinguish between those two cases.

}
}

Expand Down
64 changes: 57 additions & 7 deletions subsys/sal/sid_pal/src/sid_ble_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include <sid_error.h>
#include <sid_ble_config_ifc.h>
#include <sid_pal_ble_adapter_ifc.h>
#include <sid_ble_service.h>
#include <sid_ble_ama_service.h>
Expand All @@ -31,7 +32,9 @@
#include <zephyr/settings/settings.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/sys/util.h>
#include <zephyr/bluetooth/hci_vs.h>
#include <string.h>

LOG_MODULE_REGISTER(sid_ble, CONFIG_SIDEWALK_BLE_ADAPTER_LOG_LEVEL);

Expand All @@ -48,21 +51,28 @@ static sid_error_t ble_adapter_deinit(void);
static sid_error_t ble_adapter_get_rssi(int8_t *rssi);
static sid_error_t ble_adapter_get_tx_pwr(int16_t *tx_power);
static sid_error_t ble_adapter_set_tx_pwr(int16_t tx_power);
static sid_error_t ble_adapter_user_config(sid_ble_user_config_t *cfg);
static void ble_adapter_received_data_result(sid_error_t result);
static void ble_adapter_notify_ama_state(bool is_active);
static sid_error_t ble_adapter_get_mac_addr(uint8_t *addr);

static struct sid_pal_ble_adapter_interface ble_ifc = {
.init = ble_adapter_init,
.start_service = ble_adapter_start_service,
.user_config = ble_adapter_user_config,
.set_adv_data = ble_adapter_set_adv_data,
.start_adv = ble_adapter_start_advertisement,
.stop_adv = ble_adapter_stop_advertisement,
.get_rssi = ble_adapter_get_rssi,
.get_tx_pwr = ble_adapter_get_tx_pwr,
.send = ble_adapter_send_data,
.set_callback = ble_adapter_set_callback,
.set_tx_pwr = ble_adapter_set_tx_pwr,
.received_data_result = ble_adapter_received_data_result,
.disconnect = ble_adapter_disconnect,
.deinit = ble_adapter_deinit,
.get_rssi = ble_adapter_get_rssi,
.get_tx_pwr = ble_adapter_get_tx_pwr,
.set_tx_pwr = ble_adapter_set_tx_pwr,

.notify_ama_state = ble_adapter_notify_ama_state,
.get_mac_addr = ble_adapter_get_mac_addr,
};

static void read_conn_rssi(uint16_t handle, int8_t *rssi)
Expand Down Expand Up @@ -379,6 +389,44 @@ static sid_error_t ble_adapter_send_data(sid_ble_cfg_service_identifier_t id, ui
return SID_ERROR_NONE;
}

static sid_error_t ble_adapter_user_config(sid_ble_user_config_t *cfg)
{
ARG_UNUSED(cfg);
LOG_DBG("BLE user config: not implemented");
return SID_ERROR_NOSUPPORT;
}

static void ble_adapter_received_data_result(sid_error_t result)
{
ARG_UNUSED(result);
LOG_DBG("received_data_result: not implemented");
}

static void ble_adapter_notify_ama_state(bool is_active)
{
ARG_UNUSED(is_active);
LOG_DBG("notify_ama_state: not implemented");
}

static sid_error_t ble_adapter_get_mac_addr(uint8_t *addr)
{
if (!addr) {
return SID_ERROR_NULL_POINTER;
}

bt_addr_le_t addrs[BT_ID_SIDEWALK + 1];
size_t count = ARRAY_SIZE(addrs);

bt_id_get(addrs, &count);
if (count <= BT_ID_SIDEWALK) {
LOG_WRN("get_mac_addr: Sidewalk identity not present (count=%zu)", count);
return SID_ERROR_NOT_FOUND;
}

memcpy(addr, addrs[BT_ID_SIDEWALK].a.val, BLE_ADDR_MAX_LEN);
return SID_ERROR_NONE;
}

static sid_error_t ble_adapter_set_callback(const sid_pal_ble_adapter_callbacks_t *cb)
{
LOG_DBG("Sidewalk -> BLE");
Expand Down Expand Up @@ -441,11 +489,13 @@ static sid_error_t ble_adapter_deinit(void)
sid_ble_advert_deinit();
bt_id_delete(BT_ID_SIDEWALK);
bt_id_reset(BT_ID_SIDEWALK, NULL, NULL);
int err = sid_ble_bt_disable();
int ret = sid_ble_bt_disable();

if (err) {
LOG_ERR("BT disable failed (error %d)", err);
if (ret < 0) {
LOG_ERR("BT disable failed (error %d)", ret);
return SID_ERROR_GENERIC;
} else if (ret > 0) {
LOG_WRN("Sidewalk ble adapter disabled, but BT still enabled (ret=%d)", ret);
}

return SID_ERROR_NONE;
Expand Down
22 changes: 21 additions & 1 deletion tests/unit_tests/sid_dut_shell/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,27 @@ config SIDEWALK_LOG_LEVEL


config SBDT_MAX_PARALEL_TRANSFERS
int
int
default 3

config SIDEWALK_BLE_ADV_INT_FAST
int "Fast advertise interval in ms"
default 160

config SIDEWALK_BLE_ADV_INT_SLOW
int "Slow advertise interval in ms"
default 1000

config SIDEWALK_BLE_ADV_INT_TRANSITION
int "Duration of fast advertisement after sid_start in seconds"
default 30

config BT_PERIPHERAL_PREF_LATENCY
int "Preferred slave latency"
default 0

config BT_PERIPHERAL_PREF_TIMEOUT
int "Preferred supervision timeout in 10 ms units"
default 400

source "Kconfig.zephyr"