Skip to content

Commit 3833ee0

Browse files
committed
sal: sid_pal: add missing ble adapter functions
- Updated the BLE adapter interface to include a user config. - Added a new known issue regarding unsupported Sidewalk option for BLE config in NCS. - Introduced a new command for setting BLE user config in dut. Signed-off-by: Krzysztof Taborowski <krzysztof.taborowski@nordicsemi.no>
1 parent c7dd8cc commit 3833ee0

File tree

4 files changed

+133
-4
lines changed

4 files changed

+133
-4
lines changed

doc/known_issues.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ KRKNWK-21160: Semtech interrupt pin remains high blocking the Wi-Fi scan.
7373

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

76+
KRKNWK-21514: Sidewalk option for Bluetooth LE config (``SID_OPTION_BLE_USER_CONFIG``) is not supported in the NCS
77+
Calling the Sidewalk Kconfig option ``SID_OPTION_BLE_USER_CONFIG`` causes the application to crash.
78+
79+
**Affected platforms:** All platforms.
80+
7681
List of known issues for v1.0.1
7782
*******************************
7883

samples/sid_end_device/include/cli/app_shell.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@
229229
#define CMD_SID_SET_OPTION_LP_SET_ARG_OPTIONAL 1
230230
#define CMD_SID_OPTION_GSI_ARG_REQUIRED 1
231231
#define CMD_SID_OPTION_GSI_ARG_OPTIONAL 0
232+
#define CMD_SID_OPTION_BLE_CFG_DESCRIPTION \
233+
"set <cfg_type> [inactivity_timeout]\n" \
234+
"Set BLE user config (SID_OPTION_BLE_USER_CONFIG).\n" \
235+
"<cfg_type> 0=ADV, 1=CONN, 2=ADV_AND_CONN, 3=INACTIVITY_TIMEOUT.\n" \
236+
"For cfg_type 3, <inactivity_timeout> (seconds) is required."
237+
#define CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED 2
238+
#define CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL 1
232239
#define CMD_SID_LAST_STATUS_ARG_REQUIRED 1
233240
#define CMD_SID_LAST_STATUS_ARG_OPTIONAL 0
234241
#define CMD_SID_CONN_REQUEST_ARG_REQUIRED 2
@@ -271,6 +278,7 @@ int cmd_sid_option_c(const struct shell *shell, int32_t argc, const char **argv)
271278
int cmd_sid_option_ml(const struct shell *shell, int32_t argc, const char **argv);
272279
int cmd_sid_option_gc(const struct shell *shell, int32_t argc, const char **argv);
273280
int cmd_sid_option_sid_id(const struct shell *shell, int32_t argc, const char **argv);
281+
int cmd_sid_option_ble_cfg_set(const struct shell *shell, int32_t argc, const char **argv);
274282

275283
int cmd_sid_last_status(const struct shell *shell, int32_t argc, const char **argv);
276284
int cmd_sid_conn_request(const struct shell *shell, int32_t argc, const char **argv);

samples/sid_end_device/src/cli/app_shell.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <sid_api.h>
1818
#include <sid_900_cfg.h>
19+
#include <sid_ble_config_ifc.h>
1920
#include <sid_hal_memory_ifc.h>
2021

2122
#include <cli/app_shell.h>
@@ -79,6 +80,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
7980
CMD_SID_SET_OPTION_GC_ARG_REQUIRED, CMD_SID_SET_OPTION_GC_ARG_OPTIONAL),
8081
SHELL_CMD_ARG(-gsi, NULL, CMD_SID_OPTION_GSI_DESCRIPTION, cmd_sid_option_sid_id,
8182
CMD_SID_OPTION_GSI_ARG_REQUIRED, CMD_SID_OPTION_GSI_ARG_OPTIONAL),
83+
SHELL_CMD_ARG(-ble_cfg, NULL, CMD_SID_OPTION_BLE_CFG_DESCRIPTION,
84+
cmd_sid_option_ble_cfg_set, CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED,
85+
CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL),
8286

8387
SHELL_SUBCMD_SET_END);
8488

@@ -989,6 +993,70 @@ int cmd_sid_option_gc(const struct shell *shell, int32_t argc, const char **argv
989993
return 0;
990994
}
991995

996+
#define BLE_CFG_MS_TO_ADV_INTERVAL(ms) ((uint32_t)(((ms) * 8U) / 5U))
997+
#define BLE_CFG_MS_TO_CONN_INTERVAL(ms) ((uint16_t)(((ms) * 8U) / 5U))
998+
999+
int cmd_sid_option_ble_cfg_set(const struct shell *shell, int32_t argc, const char **argv)
1000+
{
1001+
CHECK_ARGUMENT_COUNT(argc, CMD_SID_OPTION_BLE_CFG_ARG_REQUIRED,
1002+
CMD_SID_OPTION_BLE_CFG_ARG_OPTIONAL);
1003+
1004+
if (strcmp(argv[1], "set") != 0) {
1005+
shell_error(shell, "First argument must be 'set'");
1006+
return -EINVAL;
1007+
}
1008+
1009+
long cfg_type_raw = 0l;
1010+
char *end = NULL;
1011+
cfg_type_raw = strtol(argv[2], &end, 0);
1012+
if (end == argv[2] || !IN_RANGE(cfg_type_raw, SID_BLE_USER_CFG_ADV,
1013+
SID_BLE_USER_CFG_INACTIVITY_TIMEOUT)) {
1014+
shell_error(shell, "cfg_type must be 0..3 (ADV, CONN, ADV_AND_CONN, INACTIVITY_TIMEOUT)");
1015+
return -EINVAL;
1016+
}
1017+
1018+
struct sid_ble_user_config cfg = {
1019+
.adv_param = {
1020+
.type = AMA_SERVICE,
1021+
.fast_enabled = true,
1022+
.slow_enabled = true,
1023+
.fast_interval = BLE_CFG_MS_TO_ADV_INTERVAL(CONFIG_SIDEWALK_BLE_ADV_INT_FAST),
1024+
.fast_timeout = CONFIG_SIDEWALK_BLE_ADV_INT_TRANSITION * 100, /* seconds to 10ms */
1025+
.slow_interval = BLE_CFG_MS_TO_ADV_INTERVAL(CONFIG_SIDEWALK_BLE_ADV_INT_SLOW),
1026+
.slow_timeout = 0,
1027+
},
1028+
.conn_param = {
1029+
.min_conn_interval = BLE_CFG_MS_TO_CONN_INTERVAL(CONFIG_SIDEWALK_BLE_ADV_INT_SLOW),
1030+
.max_conn_interval = BLE_CFG_MS_TO_CONN_INTERVAL(CONFIG_SIDEWALK_BLE_ADV_INT_FAST),
1031+
.slave_latency = CONFIG_BT_PERIPHERAL_PREF_LATENCY,
1032+
.conn_sup_timeout = CONFIG_BT_PERIPHERAL_PREF_TIMEOUT,
1033+
},
1034+
.is_set = true,
1035+
.cfg_type = (enum sid_ble_user_config_type)cfg_type_raw,
1036+
.inactivity_timeout = 0,
1037+
};
1038+
1039+
if (cfg.cfg_type == SID_BLE_USER_CFG_INACTIVITY_TIMEOUT) {
1040+
if (argc < 4) {
1041+
shell_error(shell, "inactivity_timeout required for cfg_type 3");
1042+
return -EINVAL;
1043+
}
1044+
unsigned long timeout = strtoul(argv[3], &end, 0);
1045+
if (end == argv[3] || timeout > UINT32_MAX) {
1046+
shell_error(shell, "Invalid inactivity_timeout");
1047+
return -EINVAL;
1048+
}
1049+
cfg.inactivity_timeout = (uint32_t)timeout;
1050+
}
1051+
1052+
int err = cmd_sid_option_set(SID_OPTION_BLE_USER_CONFIG, &cfg, sizeof(cfg));
1053+
if (err) {
1054+
shell_error(shell, "event err %d", err);
1055+
}
1056+
1057+
return 0;
1058+
}
1059+
9921060
int cmd_sid_last_status(const struct shell *shell, int32_t argc, const char **argv)
9931061
{
9941062
CHECK_ARGUMENT_COUNT(argc, CMD_SID_LAST_STATUS_ARG_REQUIRED,

subsys/sal/sid_pal/src/sid_ble_adapter.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include <sid_error.h>
12+
#include <sid_ble_config_ifc.h>
1213
#include <sid_pal_ble_adapter_ifc.h>
1314
#include <sid_ble_service.h>
1415
#include <sid_ble_ama_service.h>
@@ -31,7 +32,9 @@
3132
#include <zephyr/settings/settings.h>
3233
#include <zephyr/logging/log.h>
3334
#include <zephyr/sys/byteorder.h>
35+
#include <zephyr/sys/util.h>
3436
#include <zephyr/bluetooth/hci_vs.h>
37+
#include <string.h>
3538

3639
LOG_MODULE_REGISTER(sid_ble, CONFIG_SIDEWALK_BLE_ADAPTER_LOG_LEVEL);
3740

@@ -48,21 +51,28 @@ static sid_error_t ble_adapter_deinit(void);
4851
static sid_error_t ble_adapter_get_rssi(int8_t *rssi);
4952
static sid_error_t ble_adapter_get_tx_pwr(int16_t *tx_power);
5053
static sid_error_t ble_adapter_set_tx_pwr(int16_t tx_power);
54+
static sid_error_t ble_adapter_user_config(sid_ble_user_config_t *cfg);
55+
static void ble_adapter_received_data_result(sid_error_t result);
56+
static void ble_adapter_notify_ama_state(bool is_active);
57+
static sid_error_t ble_adapter_get_mac_addr(uint8_t *addr);
5158

5259
static struct sid_pal_ble_adapter_interface ble_ifc = {
5360
.init = ble_adapter_init,
5461
.start_service = ble_adapter_start_service,
62+
.user_config = ble_adapter_user_config,
5563
.set_adv_data = ble_adapter_set_adv_data,
5664
.start_adv = ble_adapter_start_advertisement,
5765
.stop_adv = ble_adapter_stop_advertisement,
66+
.get_rssi = ble_adapter_get_rssi,
67+
.get_tx_pwr = ble_adapter_get_tx_pwr,
5868
.send = ble_adapter_send_data,
5969
.set_callback = ble_adapter_set_callback,
70+
.set_tx_pwr = ble_adapter_set_tx_pwr,
71+
.received_data_result = ble_adapter_received_data_result,
6072
.disconnect = ble_adapter_disconnect,
6173
.deinit = ble_adapter_deinit,
62-
.get_rssi = ble_adapter_get_rssi,
63-
.get_tx_pwr = ble_adapter_get_tx_pwr,
64-
.set_tx_pwr = ble_adapter_set_tx_pwr,
65-
74+
.notify_ama_state = ble_adapter_notify_ama_state,
75+
.get_mac_addr = ble_adapter_get_mac_addr,
6676
};
6777

6878
static void read_conn_rssi(uint16_t handle, int8_t *rssi)
@@ -379,6 +389,44 @@ static sid_error_t ble_adapter_send_data(sid_ble_cfg_service_identifier_t id, ui
379389
return SID_ERROR_NONE;
380390
}
381391

392+
static sid_error_t ble_adapter_user_config(sid_ble_user_config_t *cfg)
393+
{
394+
ARG_UNUSED(cfg);
395+
LOG_DBG("BLE user config: not implemented");
396+
return SID_ERROR_NOSUPPORT;
397+
}
398+
399+
static void ble_adapter_received_data_result(sid_error_t result)
400+
{
401+
ARG_UNUSED(result);
402+
LOG_DBG("received_data_result: not implemented");
403+
}
404+
405+
static void ble_adapter_notify_ama_state(bool is_active)
406+
{
407+
ARG_UNUSED(is_active);
408+
LOG_DBG("notify_ama_state: not implemented");
409+
}
410+
411+
static sid_error_t ble_adapter_get_mac_addr(uint8_t *addr)
412+
{
413+
if (!addr) {
414+
return SID_ERROR_NULL_POINTER;
415+
}
416+
417+
bt_addr_le_t addrs[BT_ID_SIDEWALK + 1];
418+
size_t count = ARRAY_SIZE(addrs);
419+
420+
bt_id_get(addrs, &count);
421+
if (count <= BT_ID_SIDEWALK) {
422+
LOG_WRN("get_mac_addr: Sidewalk identity not present (count=%zu)", count);
423+
return SID_ERROR_NOT_FOUND;
424+
}
425+
426+
memcpy(addr, addrs[BT_ID_SIDEWALK].a.val, BLE_ADDR_MAX_LEN);
427+
return SID_ERROR_NONE;
428+
}
429+
382430
static sid_error_t ble_adapter_set_callback(const sid_pal_ble_adapter_callbacks_t *cb)
383431
{
384432
LOG_DBG("Sidewalk -> BLE");

0 commit comments

Comments
 (0)