Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
52dc3b6
[nrf fromtree] Bluetooth: Host: Ensure conn_ready access is thread safe
Yagoor Jan 8, 2025
91d93bb
[nrf fromtree] tests: bluetooth: Add missing mocks after fix on host
Yagoor Jan 13, 2025
1d7a4ca
[nrf fromtree] bluetooth: mesh: fix mesh pb gatt cli uuid usage
m-alperen-sener Dec 13, 2024
b395df8
[nrf fromtree] tests: bluetooth: mesh: Add PB-GATT provisioning test …
m-alperen-sener Dec 11, 2024
4c7ffbd
[nrf fromtree] Bluetooth: Mesh: use settings priority feature
KyraLengfeld Dec 17, 2024
ecea727
[nrf fromtree] Bluetooth: Mesh: use secure storage in ble mesh
alxelax Nov 28, 2024
6edb3af
[nrf fromtree] tests: bluetooth: tester: Increase number of PSA key s…
m-alperen-sener Jan 10, 2025
bedb272
[nrf fromtree] bluetooth: mesh: Remove assertion for Received List me…
PavelVPV Jan 14, 2025
1c57b77
[nrf fromtree] Bluetooth: host: Add overlays for bsim tests
akredalen Jan 14, 2025
4db339d
[nrf fromtree] bluetooth: host: iterate over connections in TX list
aahmed-dewinelabs Jan 10, 2025
410a315
[nrf fromtree] bluetooth: host: add asserts to foreach in get_conn_ready
aahmed-dewinelabs Jan 16, 2025
1ef1960
[nrf fromtree] bluetooth: host: fix connection reference before retur…
aahmed-dewinelabs Jan 16, 2025
2db3b81
[nrf fromtree] Bluetooth: Mesh: Fix Assert in bt_mesh_adv_unref when …
LingaoM Jan 14, 2025
389b307
[nrf fromtree] Bluetooth: Host: bsim: Refactor common files
HaavardRei Jan 15, 2025
9c4c86c
[nrf fromtree] tests: Bluetooth: Tester: Reorder btp_buf to fix varia…
Thalley Jan 20, 2025
eb38d18
[nrf fromtree] Bluetooth: Mesh: remove experimental flag from mbedtls…
alxelax Jan 20, 2025
a7732ac
[nrf fromtree] doc: update migration guide with mesh dependency
alxelax Jan 20, 2025
2ec2f0f
[nrf fromtree] Bluetooth: Mesh: Improve logic for serving devices era…
de-nordic Dec 1, 2024
3a23e86
[nrf fromtree] Bluetooth: Host: Remove leftover HCI ECC command checks
jhedberg Jan 27, 2025
a148e59
[nrf fromtree] tests: Bluetooth: Tester: Avoid union with packed stru…
sjanc Jan 21, 2025
02fb2ee
[nrf fromtree] tests: Bluetooth: Tester: Improve BTP MTU validation
sjanc Jan 24, 2025
1c6e459
[nrf fromtree] Bluetooth: Host: Fix overwriting ECC error value
jhedberg Jan 27, 2025
82b05ee
[nrf fromtree] Bluetooth: Host: Specify parameter needs of `bt_set_name`
theob-pro Jan 10, 2025
b48d4e9
[nrf fromtree] Bluetooth: Host: GAP Device Name write now add null ch…
theob-pro Jan 15, 2025
487fe6d
[nrf fromtree] Tests: Bluetooth: Add MTU exchange procedure in testlib
theob-pro Jan 15, 2025
78f87be
[nrf fromtree] Tests: Bluetooth: Add 'device_name' GATT test
theob-pro Jan 10, 2025
58db905
[nrf fromtree] Tests: Bluetooth: Add hci_ipc config to Twister integr…
ludvigsj Jan 28, 2025
9f2dc47
[nrf fromtree] Bluetooth: Mesh: add missing device key candidate PSA …
ludvigsj Dec 17, 2024
f4d7ef5
[nrf fromtree] Bluetooth: Mesh: remove deprecated field in cdb subnet
alxelax Jan 29, 2025
9151235
[nrf fromtree] doc: update migration guide with mesh versions incompa…
alxelax Jan 29, 2025
8013e61
[nrf fromtree] Bluetooth: Host: Updated Kconfig description
Balaklaka Feb 5, 2025
a1bbbd5
[nrf fromtree] bluetooth: host: hci_core: add missing `NULL` check
JordanYates Feb 5, 2025
9feb592
[nrf fromtree] bluetooth: host/crypto: fix the psa crypto init for host
m-alperen-sener Feb 6, 2025
16208dc
[nrf fromtree] bluetooth: mesh: pb_adv: ensure that bitwise NOT doesn…
PavelVPV Feb 6, 2025
87cbc66
[nrf fromtree] bluetooth: mesh: access: cast to uint8_t to avoid pote…
PavelVPV Feb 6, 2025
5fb9009
[nrf fromtree] bluetooth: mesh: proxy_msg: check that att mtu is big …
PavelVPV Feb 6, 2025
f16fdf0
[nrf fromtree] bluetooth: mesh: delayable_msg: cast to avoid truncati…
PavelVPV Feb 6, 2025
22804c7
[nrf fromtree] Bluetooth: Mesh: Remove ADV_FLAG_PROXY_START, due to m…
LingaoM Nov 13, 2024
7897388
[nrf fromtree] Bluetooth: Mesh: Remove START_PENDING flags
LingaoM Nov 13, 2024
b532acc
[nrf fromtree] tests: bsim: Add testcase for bluetooth mesh extended …
LingaoM Dec 5, 2024
ef4d2fb
[nrf fromtree] Bluetooth: Mesh: remove double cdb node storing
alxelax Feb 7, 2025
5fd7731
[nrf fromtree] Bluetooth: testlib: Add addr string macro
HaavardRei Feb 10, 2025
aea9999
[nrf fromtree] Bluetooth: tests: Add macros to babblekit
HaavardRei Feb 10, 2025
eeb2e38
[nrf fromtree] Bluetooth: Host: More bsim refactoring
HaavardRei Feb 6, 2025
d0f05c3
[nrf fromtree] tests: bluetooth: tester: mesh: Increase CMD tx bufs
PavelVPV Feb 10, 2025
e333a51
[nrf fromtree] tests: bluetooth: tester: Make BTP CMD thread stack si…
m-alperen-sener Feb 7, 2025
9bbff7d
[nrf fromtree] Bluetooth: Mesh: Remove experimental TF-M PSA
Balaklaka Feb 5, 2025
fc294e1
[nrf fromtree] bluetooth: mesh: Correct callback check mesh blob client
m-alperen-sener Feb 12, 2025
615d949
[nrf noup] samples: bluetooth: mesh: Disable secure storage for real …
m-alperen-sener Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions doc/connectivity/bluetooth/api/mesh/dfu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ re-provisioned. The complete list of available options is defined in :c:enum:`bt
provisioning. In this case, the device stays provisioned and the new composition data takes place
after re-provisioning using the Remote Provisioning models.
:c:enumerator:`BT_MESH_DFU_EFFECT_UNPROV`
This effect is chosen if the composition data in the new firmware changes, the device doesn't
This effect is chosen if the composition data in the new firmware changes, the device does not
support the remote provisioning, and the new composition data takes effect after applying the
firmware.
firmware. The effect can also be chosen, if it is necessary to unprovision the device for
application-specific reasons.

When the Target node receives the Firmware Update Firmware Metadata Check message, the Firmware
Update Server model calls the :c:member:`bt_mesh_dfu_srv_cb.check` callback, the application can
Expand Down
15 changes: 15 additions & 0 deletions doc/releases/migration-guide-4.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ Bluetooth Mesh
set as deprecated. Default option for platforms that do not support TF-M
is :kconfig:option:`CONFIG_BT_MESH_USES_MBEDTLS_PSA`.

* Mesh key representations are not backward compatible if images are built with TinyCrypt and
crypto libraries based on the PSA API. Mesh no longer stores the key values for those crypto
libraries. The crypto library stores the keys in the internal trusted storage.
If a provisioned device is going to update its image that was built with
the :kconfig:option:`CONFIG_BT_MESH_USES_TINYCRYPT` Kconfig option set on an image
that was built with :kconfig:option:`CONFIG_BT_MESH_USES_MBEDTLS_PSA` or
:kconfig:option:`CONFIG_BT_MESH_USES_TFM_PSA` without erasing the persistent area,
it should be unprovisioned first and reprovisioned after update again.
If the image is changed over Mesh DFU, use :c:enumerator:`BT_MESH_DFU_EFFECT_UNPROV`.

* Mesh explicitly depends on the Secure Storage subsystem if storing into
non-volatile memory (:kconfig:option:`CONFIG_BT_SETTINGS`) is enabled and
Mbed TLS library (:kconfig:option:`CONFIG_BT_MESH_USES_MBEDTLS_PSA`) is used.
Applications should be built with :kconfig:option:`CONFIG_SECURE_STORAGE` enabled.

Bluetooth Audio
===============

Expand Down
2 changes: 1 addition & 1 deletion include/zephyr/bluetooth/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool bt_is_ready(void);
*
* @sa @kconfig{CONFIG_BT_DEVICE_NAME_MAX}.
*
* @param name New name
* @param name New name, must be null terminated
*
* @return Zero on success or (negative) error code otherwise.
*/
Expand Down
2 changes: 1 addition & 1 deletion include/zephyr/bluetooth/mesh/access.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ struct bt_mesh_model_op {
* @return Mesh transmit value that can be used e.g. for the default
* values of the configuration model data.
*/
#define BT_MESH_TRANSMIT(count, int_ms) ((count) | (((int_ms / 10) - 1) << 3))
#define BT_MESH_TRANSMIT(count, int_ms) ((uint8_t)((count) | (((int_ms / 10) - 1) << 3)))

/**
* @brief Decode transmit count from a transmit value.
Expand Down
6 changes: 0 additions & 6 deletions modules/mbedtls/configs/config-tls-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,6 @@
#define MBEDTLS_PSA_P256M_DRIVER_ENABLED
#endif

#if defined(CONFIG_ARCH_POSIX) && !defined(CONFIG_PICOLIBC) && !defined(CONFIG_SECURE_STORAGE)
#define MBEDTLS_PSA_ITS_FILE_C
#define MBEDTLS_PSA_CRYPTO_STORAGE_C
#define MBEDTLS_FS_IO
#endif

#if defined(CONFIG_SECURE_STORAGE)
#define MBEDTLS_PSA_CRYPTO_STORAGE_C
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SECURE_STORAGE=n
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh/boards/qemu_x86.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# nrf_security only supports Cortex-M via PSA crypto libraries.
# Enforcing usage of built-in Mbed TLS for native simulator.
CONFIG_NRF_SECURITY=n
CONFIG_MBEDTLS_ENABLE_HEAP=n
CONFIG_TRUSTED_STORAGE=n
CONFIG_SECURE_STORAGE=y
1 change: 1 addition & 0 deletions samples/bluetooth/mesh/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
# CONFIG_SECURE_STORAGE=y
CONFIG_HWINFO=y

CONFIG_BT=y
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SECURE_STORAGE=n
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh_demo/boards/qemu_x86.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# nrf_security only supports Cortex-M via PSA crypto libraries.
# Enforcing usage of built-in Mbed TLS for native simulator.
CONFIG_NRF_SECURITY=n
CONFIG_MBEDTLS_ENABLE_HEAP=n
CONFIG_TRUSTED_STORAGE=n
CONFIG_SECURE_STORAGE=y
1 change: 1 addition & 0 deletions samples/bluetooth/mesh_demo/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600
# CONFIG_SECURE_STORAGE=y

# Limit the number of key slots in PSA Crypto core to reduce
# RAM footprint
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SECURE_STORAGE=n
6 changes: 6 additions & 0 deletions samples/bluetooth/mesh_provisioner/boards/qemu_x86.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# nrf_security only supports Cortex-M via PSA crypto libraries.
# Enforcing usage of built-in Mbed TLS for native simulator.
CONFIG_NRF_SECURITY=n
CONFIG_MBEDTLS_ENABLE_HEAP=n
CONFIG_TRUSTED_STORAGE=n
CONFIG_SECURE_STORAGE=y
1 change: 1 addition & 0 deletions samples/bluetooth/mesh_provisioner/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600
# CONFIG_SECURE_STORAGE=y

#CONFIG_BT_MESH_LOG_LEVEL_DBG=y
#CONFIG_BT_MESH_SETTINGS_LOG_LEVEL_DBG=y
Expand Down
2 changes: 2 additions & 0 deletions samples/boards/nordic/mesh/onoff-app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
# CONFIG_SECURE_STORAGE=y

CONFIG_BT_MESH_RPL_STORE_TIMEOUT=600

CONFIG_BOOT_BANNER=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
# CONFIG_SECURE_STORAGE=y

CONFIG_BT_OBSERVER=y
CONFIG_BT_BROADCASTER=y
Expand Down
1 change: 1 addition & 0 deletions samples/boards/phytec/reel_board/mesh_badge/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SECURE_STORAGE=y
CONFIG_CBPRINTF_FP_SUPPORT=y
19 changes: 19 additions & 0 deletions subsys/bluetooth/common/bt_settings_commit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright (c) 2024 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef BT_SETTINGS_COMMIT_H_
#define BT_SETTINGS_COMMIT_H_

/**
* @brief Bluetooth Settings Commit Priorities
*
* Enum of commit priorities for Bluetooth settings handlers.
* Lower values indicate higher priority.
*/
enum bt_settings_commit_priority {
BT_SETTINGS_CPRIO_0,
BT_SETTINGS_CPRIO_1,
BT_SETTINGS_CPRIO_2,
};

#endif /* BT_SETTINGS_COMMIT_H_ */
8 changes: 6 additions & 2 deletions subsys/bluetooth/host/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ config BT_RECV_WORKQ_SYS
High priority HCI packets will processed in the context of the caller of bt_recv().
The application needs to ensure the system workqueue stack size (SYSTEM_WORKQUEUE_STACK_SIZE)
is large enough, refer to BT_RX_STACK_SIZE for the recommended minimum.
Note: When this option is used, other users of the system work queue will influence the
latency of incoming Bluetooth events.
Warning: Enabling this option will cause the latency of incoming Bluetooth events to be
affected by other tasks using the system work queue. When this option is active, the Host
will process Bluetooth events in a blocking manner. This can lead to deadlocks if the
application waits for the system work queue while handling Bluetooth events. This feature
is intended for advanced users to allow aggressive memory optimization for devices with
very limited memory. It is strongly advised not to use this option.

config BT_RECV_WORKQ_BT
bool "Process low priority HCI packets in the bluetooth-specific work queue"
Expand Down
90 changes: 48 additions & 42 deletions subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,18 @@ void bt_conn_data_ready(struct bt_conn *conn)
*
* This reference will be consumed when the conn is popped off
* the list (in `get_conn_ready`).
*
* The `bt_dev.le.conn_ready` list is accessed by the tx_processor
* which runs in a workqueue, but `bt_conn_data_ready` can be called
* from different threads so we need to make sure that nothing will
* trigger a thread switch while we are manipulating the list since
* sys_slist_*() functions are not thread safe.
*/
bt_conn_ref(conn);
k_sched_lock();
sys_slist_append(&bt_dev.le.conn_ready,
&conn->_conn_ready);
k_sched_unlock();
LOG_DBG("raised");
} else {
LOG_DBG("already in list");
Expand Down Expand Up @@ -910,22 +918,8 @@ __maybe_unused static bool dont_have_methods(struct bt_conn *conn)

struct bt_conn *get_conn_ready(void)
{
/* Here we only peek: we pop the conn (and insert it at the back if it
* still has data) after the QoS function returns false.
*/
sys_snode_t *node = sys_slist_peek_head(&bt_dev.le.conn_ready);

if (node == NULL) {
return NULL;
}

/* `conn` borrows from the list node. That node is _not_ popped yet.
*
* If we end up not popping that conn off the list, we have to make sure
* to increase the refcount before returning a pointer to that
* connection out of this function.
*/
struct bt_conn *conn = CONTAINER_OF(node, struct bt_conn, _conn_ready);
struct bt_conn *conn, *tmp;
sys_snode_t *prev = NULL;

if (dont_have_viewbufs()) {
/* We will get scheduled again when the (view) buffers are freed. If you
Expand All @@ -935,42 +929,54 @@ struct bt_conn *get_conn_ready(void)
return NULL;
}

if (cannot_send_to_controller(conn)) {
/* We will get scheduled again when the buffers are freed. */
LOG_DBG("no LL bufs for %p", conn);
return NULL;
}
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&bt_dev.le.conn_ready, conn, tmp, _conn_ready) {
__ASSERT_NO_MSG(tmp != conn);

if (dont_have_tx_context(conn)) {
/* We will get scheduled again when TX contexts are available. */
LOG_DBG("no TX contexts");
return NULL;
}
/* Iterate over the list of connections that have data to send
* and return the first one that can be sent.
*/

CHECKIF(dont_have_methods(conn)) {
LOG_DBG("conn %p (type %d) is missing mandatory methods",
conn, conn->type);
if (cannot_send_to_controller(conn)) {
/* When buffers are full, try next connection. */
LOG_DBG("no LL bufs for %p", conn);
prev = &conn->_conn_ready;
continue;
}

return NULL;
}
if (dont_have_tx_context(conn)) {
/* When TX contexts are not available, try next connection. */
LOG_DBG("no TX contexts for %p", conn);
prev = &conn->_conn_ready;
continue;
}

if (should_stop_tx(conn)) {
/* Move reference off the list and into the `conn` variable. */
__maybe_unused sys_snode_t *s = sys_slist_get(&bt_dev.le.conn_ready);
CHECKIF(dont_have_methods(conn)) {
/* When a connection is missing mandatory methods, try next connection. */
LOG_DBG("conn %p (type %d) is missing mandatory methods", conn, conn->type);
prev = &conn->_conn_ready;
continue;
}

if (should_stop_tx(conn)) {
/* Move reference off the list */
__ASSERT_NO_MSG(prev != &conn->_conn_ready);
sys_slist_remove(&bt_dev.le.conn_ready, prev, &conn->_conn_ready);
(void)atomic_set(&conn->_conn_ready_lock, 0);

__ASSERT_NO_MSG(s == node);
(void)atomic_set(&conn->_conn_ready_lock, 0);
/* Append connection to list if it still has data */
if (conn->has_data(conn)) {
LOG_DBG("appending %p to back of TX queue", conn);
bt_conn_data_ready(conn);
}

/* Append connection to list if it still has data */
if (conn->has_data(conn)) {
LOG_DBG("appending %p to back of TX queue", conn);
bt_conn_data_ready(conn);
return conn;
}

return conn;
return bt_conn_ref(conn);
}

return bt_conn_ref(conn);
/* No connection has data to send */
return NULL;
}

/* Crazy that this file is compiled even if this is not true, but here we are. */
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* SPDX-License-Identifier: Apache-2.0
*/

int prng_init(void);
int bt_crypto_init(void);
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/crypto_psa.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_host_crypto);

int prng_init(void)
int bt_crypto_init(void)
{
psa_status_t status = psa_crypto_init();

Expand Down
16 changes: 6 additions & 10 deletions subsys/bluetooth/host/ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ static void generate_dh_key(struct k_work *work)
if (ret != PSA_SUCCESS) {
LOG_ERR("Failed to destroy the key %d", ret);
err = -EIO;
goto exit;
}

err = 0;
Expand Down Expand Up @@ -252,14 +253,10 @@ int bt_pub_key_gen(struct bt_pub_key_cb *new_cb)
struct bt_pub_key_cb *cb;

if (IS_ENABLED(CONFIG_BT_USE_DEBUG_KEYS)) {
if (!BT_CMD_TEST(bt_dev.supported_commands, 41, 2)) {
LOG_WRN("ECC Debug keys HCI command not available");
} else {
atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY);
__ASSERT_NO_MSG(new_cb->func != NULL);
new_cb->func(debug_public_key);
return 0;
}
atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY);
__ASSERT_NO_MSG(new_cb->func != NULL);
new_cb->func(debug_public_key);
return 0;
}

if (!new_cb) {
Expand Down Expand Up @@ -312,8 +309,7 @@ void bt_pub_key_hci_disrupted(void)

const uint8_t *bt_pub_key_get(void)
{
if (IS_ENABLED(CONFIG_BT_USE_DEBUG_KEYS) &&
BT_CMD_TEST(bt_dev.supported_commands, 41, 2)) {
if (IS_ENABLED(CONFIG_BT_USE_DEBUG_KEYS)) {
return debug_public_key;
}

Expand Down
14 changes: 8 additions & 6 deletions subsys/bluetooth/host/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,24 @@ static ssize_t read_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,

#if defined(CONFIG_BT_DEVICE_NAME_GATT_WRITABLE)

static ssize_t write_name(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags)
static ssize_t write_name(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf,
uint16_t len, uint16_t offset, uint8_t flags)
{
char value[CONFIG_BT_DEVICE_NAME_MAX] = {};
/* adding one to fit the terminating null character */
char value[CONFIG_BT_DEVICE_NAME_MAX + 1] = {};

if (offset >= sizeof(value)) {
if (offset >= CONFIG_BT_DEVICE_NAME_MAX) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
}

if (offset + len >= sizeof(value)) {
if (offset + len > CONFIG_BT_DEVICE_NAME_MAX) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(value, buf, len);

value[len] = '\0';

bt_set_name(value);

return len;
Expand Down
Loading