Skip to content

Commit

Permalink
bluetooth: host: Add support for CS set default settings
Browse files Browse the repository at this point in the history
Added support for a new API for setting default channel
sounding settings, this is mainly a wrapper around the HCI
command.

For this add a new module for channel sounding, where new
channel sounding APIs will go.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
  • Loading branch information
sean-madigan authored and aescolar committed Sep 16, 2024
1 parent 7dff1c1 commit aedb330
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
86 changes: 86 additions & 0 deletions include/zephyr/bluetooth/cs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/** @file
* @brief Bluetooth Channel Sounding handling
*/

/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_CS_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_CS_H_

/**
* @brief Channel Sounding (CS)
* @defgroup bt_cs Channel Sounding (CS)
* @ingroup bluetooth
* @{
*/

#include <stdint.h>
#include <stdbool.h>

#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/bluetooth/conn.h>

#ifdef __cplusplus
extern "C" {
#endif

enum bt_cs_sync_antenna_selection_opt {
/** Use antenna identifier 1 for CS_SYNC packets. */
BT_CS_ANTENNA_SELECTION_OPT_ONE = BT_HCI_OP_LE_CS_ANTENNA_SEL_ONE,
/** Use antenna identifier 2 for CS_SYNC packets. */
BT_CS_ANTENNA_SELECTION_OPT_TWO = BT_HCI_OP_LE_CS_ANTENNA_SEL_TWO,
/** Use antenna identifier 3 for CS_SYNC packets. */
BT_CS_ANTENNA_SELECTION_OPT_THREE = BT_HCI_OP_LE_CS_ANTENNA_SEL_THREE,
/** Use antenna identifier 4 for CS_SYNC packets. */
BT_CS_ANTENNA_SELECTION_OPT_FOUR = BT_HCI_OP_LE_CS_ANTENNA_SEL_FOUR,
/** Use antennas in repetitive order from 1 to 4 for CS_SYNC packets. */
BT_CS_ANTENNA_SELECTION_OPT_REPETITIVE = BT_HCI_OP_LE_CS_ANTENNA_SEL_REP,
/** No recommendation for local controller antenna selection. */
BT_CS_ANTENNA_SELECTION_OPT_NO_RECOMMENDATION = BT_HCI_OP_LE_CS_ANTENNA_SEL_NONE,
};

/** Default CS settings in the local Controller */
struct bt_cs_set_default_settings_param {
/** Enable CS initiator role. */
bool enable_initiator_role;
/** Enable CS reflector role. */
bool enable_reflector_role;
/** Antenna identifier to be used for CS_SYNC packets by the local controller.
*/
enum bt_cs_sync_antenna_selection_opt cs_sync_antenna_selection;
/** Maximum output power (Effective Isotropic Radiated Power) to be used
* for all CS transmissions.
*
* Value range is @ref BT_HCI_OP_LE_CS_MIN_MAX_TX_POWER to
* @ref BT_HCI_OP_LE_CS_MAX_MAX_TX_POWER.
*/
int8_t max_tx_power;
};

/** @brief Set Channel Sounding default settings.
*
* This command is used to set default Channel Sounding settings for this
* connection.
*
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
*
* @param conn Connection Object.
* @param params Channel sounding default settings parameters.
*
* @return Zero on success or (negative) error code on failure.
*/
int bt_cs_set_default_settings(struct bt_conn *conn,
const struct bt_cs_set_default_settings_param *params);

#ifdef __cplusplus
}
#endif

/**
* @}
*/

#endif /* ZEPHYR_INCLUDE_BLUETOOTH_CS_H_ */
22 changes: 22 additions & 0 deletions include/zephyr/bluetooth/hci_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,28 @@ struct bt_hci_cp_le_tx_test_v4_tx_power {
int8_t tx_power;
} __packed;

#define BT_HCI_OP_LE_CS_SET_DEFAULT_SETTINGS BT_OP(BT_OGF_LE, 0x008D) /* 0x208D */

#define BT_HCI_OP_LE_CS_INITIATOR_ROLE_MASK BIT(0)
#define BT_HCI_OP_LE_CS_REFLECTOR_ROLE_MASK BIT(1)

#define BT_HCI_OP_LE_CS_MIN_MAX_TX_POWER -127
#define BT_HCI_OP_LE_CS_MAX_MAX_TX_POWER 20

#define BT_HCI_OP_LE_CS_ANTENNA_SEL_ONE 0x01
#define BT_HCI_OP_LE_CS_ANTENNA_SEL_TWO 0x02
#define BT_HCI_OP_LE_CS_ANTENNA_SEL_THREE 0x03
#define BT_HCI_OP_LE_CS_ANTENNA_SEL_FOUR 0x04
#define BT_HCI_OP_LE_CS_ANTENNA_SEL_REP 0xFE
#define BT_HCI_OP_LE_CS_ANTENNA_SEL_NONE 0xFF

struct bt_hci_cp_le_cs_set_default_settings {
uint16_t handle;
uint8_t role_enable;
uint8_t cs_sync_antenna_selection;
int8_t max_tx_power;
} __packed;

/* Event definitions */

#define BT_HCI_EVT_UNKNOWN 0x00
Expand Down
5 changes: 5 additions & 0 deletions subsys/bluetooth/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ if(CONFIG_BT_HCI_HOST)
conn.c
)

zephyr_library_sources_ifdef(
CONFIG_BT_CHANNEL_SOUNDING
cs.c
)

if(CONFIG_BT_DF)
zephyr_library_sources(
direction.c
Expand Down
44 changes: 44 additions & 0 deletions subsys/bluetooth/host/cs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* cs.c - Bluetooth Channel Sounding handling */

/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/byteorder.h>
#include <zephyr/bluetooth/cs.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/hci_types.h>

#include "conn_internal.h"

#if defined(CONFIG_BT_CHANNEL_SOUNDING)
int bt_cs_set_default_settings(struct bt_conn *conn,
const struct bt_cs_set_default_settings_param *params)
{
struct bt_hci_cp_le_cs_set_default_settings *cp;
struct net_buf *buf;

buf = bt_hci_cmd_create(BT_HCI_OP_LE_CS_SET_DEFAULT_SETTINGS, sizeof(*cp));
if (!buf) {
return -ENOBUFS;
}

cp = net_buf_add(buf, sizeof(*cp));
cp->handle = sys_cpu_to_le16(conn->handle);
cp->max_tx_power = params->max_tx_power;
cp->cs_sync_antenna_selection = params->cs_sync_antenna_selection;
cp->role_enable = 0;

if (params->enable_initiator_role) {
cp->role_enable |= BT_HCI_OP_LE_CS_INITIATOR_ROLE_MASK;
}

if (params->enable_reflector_role) {
cp->role_enable |= BT_HCI_OP_LE_CS_REFLECTOR_ROLE_MASK;
}

return bt_hci_cmd_send_sync(BT_HCI_OP_LE_CS_SET_DEFAULT_SETTINGS, buf, NULL);
}
#endif /* CONFIG_BT_CHANNEL_SOUNDING */

0 comments on commit aedb330

Please sign in to comment.