Skip to content

Commit 4a413c5

Browse files
Mirlenkorlubos
authored andcommitted
samples: bluetooth: cs: minor fixes
Add ARG_UNUSED for unused parameters in functions; add some more bounds checks; fix include (do not rely on transitive includes). Signed-off-by: Aleksandr Mirlenko <aleksandr.mirlenko@nordicsemi.no>
1 parent 542d107 commit 4a413c5

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

  • samples/bluetooth/channel_sounding

samples/bluetooth/channel_sounding/ipt_initiator/src/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <zephyr/types.h>
1515
#include <zephyr/sys/byteorder.h>
1616
#include <zephyr/sys/reboot.h>
17+
#include <zephyr/bluetooth/bluetooth.h>
1718
#include <zephyr/bluetooth/cs.h>
1819
#include <zephyr/bluetooth/conn.h>
1920
#include <bluetooth/scan.h>
@@ -198,6 +199,7 @@ static void subevent_steps_parse(struct bt_conn_le_cs_subevent_result *result)
198199

199200
static void subevent_result_cb(struct bt_conn *conn, struct bt_conn_le_cs_subevent_result *result)
200201
{
202+
ARG_UNUSED(conn);
201203
static int64_t prev_ts = -1;
202204
static uint32_t prev_procedure_counter = UINT16_MAX + 1;
203205

@@ -469,6 +471,7 @@ static void procedure_enable_cb(struct bt_conn *conn, uint8_t status,
469471
static void scan_filter_match(struct bt_scan_device_info *device_info,
470472
struct bt_scan_filter_match *filter_match, bool connectable)
471473
{
474+
ARG_UNUSED(filter_match);
472475
char addr[BT_ADDR_LE_STR_LEN];
473476

474477
(void)bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));
@@ -478,6 +481,7 @@ static void scan_filter_match(struct bt_scan_device_info *device_info,
478481

479482
static void scan_connecting_error(struct bt_scan_device_info *device_info)
480483
{
484+
ARG_UNUSED(device_info);
481485
int err;
482486

483487
LOG_INF("Connecting failed, restarting scanning");
@@ -491,6 +495,8 @@ static void scan_connecting_error(struct bt_scan_device_info *device_info)
491495

492496
static void scan_connecting(struct bt_scan_device_info *device_info, struct bt_conn *conn)
493497
{
498+
ARG_UNUSED(device_info);
499+
ARG_UNUSED(conn);
494500
LOG_INF("Connecting");
495501
}
496502

@@ -518,7 +524,6 @@ static int scan_init(struct bt_scan_init_param *p_param)
518524
return 0;
519525
}
520526

521-
522527
BT_CONN_CB_DEFINE(conn_cb) = {
523528
.connected = connected_cb,
524529
.disconnected = disconnected_cb,
@@ -587,6 +592,7 @@ int main(void)
587592
LOG_ERR("Failed to encrypt connection (err %d)", err);
588593
return 0;
589594
}
595+
590596
k_sem_take(&sem_security, K_FOREVER);
591597

592598
const struct bt_le_cs_set_default_settings_param default_settings = {
@@ -622,6 +628,7 @@ int main(void)
622628
LOG_ERR("Failed to create CS config (err %d)", err);
623629
return 0;
624630
}
631+
625632
k_sem_take(&sem_config_created, K_FOREVER);
626633

627634
err = bt_le_cs_security_enable(connection);

samples/bluetooth/channel_sounding/ras_initiator/src/main.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <zephyr/types.h>
1515
#include <zephyr/sys/byteorder.h>
1616
#include <zephyr/sys/reboot.h>
17+
#include <zephyr/bluetooth/bluetooth.h>
1718
#include <zephyr/bluetooth/cs.h>
1819
#include <zephyr/bluetooth/gatt.h>
1920
#include <zephyr/bluetooth/conn.h>
@@ -199,8 +200,8 @@ static void extract_pcts(cs_de_report_t *p_report, uint8_t channel_index,
199200
for (uint8_t tone_index = 0; tone_index < p_report->n_ap; tone_index++) {
200201
int antenna_path = bt_le_cs_get_antenna_path(p_report->n_ap,
201202
antenna_permutation_index, tone_index);
202-
if (antenna_path < 0) {
203-
LOG_WRN("Invalid antenna path.");
203+
if (antenna_path < 0 || antenna_path > MAX_AP) {
204+
LOG_WRN("Invalid antenna path: %d", antenna_path);
204205
return;
205206
}
206207

@@ -390,6 +391,8 @@ static void ranging_data_cb(struct bt_conn *conn, uint16_t ranging_counter, int
390391

391392
static void subevent_result_cb(struct bt_conn *conn, struct bt_conn_le_cs_subevent_result *result)
392393
{
394+
ARG_UNUSED(conn);
395+
393396
if (dropped_ranging_counter == result->header.procedure_counter) {
394397
return;
395398
}
@@ -440,6 +443,7 @@ static void subevent_result_cb(struct bt_conn *conn, struct bt_conn_le_cs_subeve
440443

441444
static void ranging_data_ready_cb(struct bt_conn *conn, uint16_t ranging_counter)
442445
{
446+
ARG_UNUSED(conn);
443447
LOG_DBG("Ranging data ready %i", ranging_counter);
444448

445449
if (ranging_counter == most_recent_local_ranging_counter) {
@@ -457,12 +461,15 @@ static void ranging_data_ready_cb(struct bt_conn *conn, uint16_t ranging_counter
457461

458462
static void ranging_data_overwritten_cb(struct bt_conn *conn, uint16_t ranging_counter)
459463
{
464+
ARG_UNUSED(conn);
460465
LOG_INF("Ranging data overwritten %i", ranging_counter);
461466
}
462467

463468
static void mtu_exchange_cb(struct bt_conn *conn, uint8_t err,
464469
struct bt_gatt_exchange_params *params)
465470
{
471+
ARG_UNUSED(params);
472+
466473
if (err) {
467474
LOG_ERR("MTU exchange failed (err %d)", err);
468475
return;
@@ -474,6 +481,8 @@ static void mtu_exchange_cb(struct bt_conn *conn, uint8_t err,
474481

475482
static void discovery_completed_cb(struct bt_gatt_dm *dm, void *context)
476483
{
484+
ARG_UNUSED(context);
485+
477486
int err;
478487

479488
LOG_INF("The discovery procedure succeeded");
@@ -497,12 +506,18 @@ static void discovery_completed_cb(struct bt_gatt_dm *dm, void *context)
497506

498507
static void discovery_service_not_found_cb(struct bt_conn *conn, void *context)
499508
{
509+
ARG_UNUSED(conn);
510+
ARG_UNUSED(context);
511+
500512
LOG_INF("The service could not be found during the discovery, disconnecting");
501513
bt_conn_disconnect(connection, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
502514
}
503515

504516
static void discovery_error_found_cb(struct bt_conn *conn, int err, void *context)
505517
{
518+
ARG_UNUSED(conn);
519+
ARG_UNUSED(context);
520+
506521
LOG_INF("The discovery procedure failed (err %d)", err);
507522
bt_conn_disconnect(connection, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
508523
}
@@ -532,6 +547,8 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_
532547
static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)
533548
{
534549
/* Ignore peer parameter preferences. */
550+
ARG_UNUSED(conn);
551+
ARG_UNUSED(param);
535552
return false;
536553
}
537554

@@ -689,6 +706,8 @@ static void procedure_enable_cb(struct bt_conn *conn,
689706

690707
void ras_features_read_cb(struct bt_conn *conn, uint32_t feature_bits, int err)
691708
{
709+
ARG_UNUSED(conn);
710+
692711
if (err) {
693712
LOG_WRN("Error while reading RAS feature bits (err %d)", err);
694713
} else {
@@ -702,6 +721,7 @@ void ras_features_read_cb(struct bt_conn *conn, uint32_t feature_bits, int err)
702721
static void scan_filter_match(struct bt_scan_device_info *device_info,
703722
struct bt_scan_filter_match *filter_match, bool connectable)
704723
{
724+
ARG_UNUSED(filter_match);
705725
char addr[BT_ADDR_LE_STR_LEN];
706726

707727
bt_addr_le_to_str(device_info->recv_info->addr, addr, sizeof(addr));
@@ -711,6 +731,7 @@ static void scan_filter_match(struct bt_scan_device_info *device_info,
711731

712732
static void scan_connecting_error(struct bt_scan_device_info *device_info)
713733
{
734+
ARG_UNUSED(device_info);
714735
int err;
715736

716737
LOG_INF("Connecting failed, restarting scanning");
@@ -724,6 +745,8 @@ static void scan_connecting_error(struct bt_scan_device_info *device_info)
724745

725746
static void scan_connecting(struct bt_scan_device_info *device_info, struct bt_conn *conn)
726747
{
748+
ARG_UNUSED(device_info);
749+
ARG_UNUSED(conn);
727750
LOG_INF("Connecting");
728751
}
729752

0 commit comments

Comments
 (0)