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
4 changes: 4 additions & 0 deletions doc/nrf-bm/release_notes/release_notes_changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ Libraries

* Updated to use errno instead of nrf_errors.

* :ref:`lib_ble_service_nus` service:

* Fixed an issue where the client context was shared between all instances.

Samples
=======

Expand Down
2 changes: 1 addition & 1 deletion include/bm/bluetooth/services/ble_nus.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct ble_nus {
/** Handles related to the RX characteristic (as provided by the SoftDevice). */
ble_gatts_char_handles_t rx_handles;
/** Link context with handles of all current connections and its context. */
struct ble_nus_ctx *const ctx;
struct ble_nus_client_context contexts[CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT];
/** Event handler to be called for handling received data. */
ble_nus_evt_handler_t evt_handler;
};
Expand Down
15 changes: 7 additions & 8 deletions subsys/bluetooth/services/ble_nus/nus.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@

LOG_MODULE_REGISTER(ble_nus, CONFIG_BLE_NUS_LOG_LEVEL);

static struct ble_nus_client_context contexts[CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT];

static struct ble_nus_client_context *ble_nus_client_context_get(uint16_t conn_handle)
static struct ble_nus_client_context *ble_nus_client_context_get(struct ble_nus *nus,
uint16_t conn_handle)
{
const int idx = nrf_sdh_ble_idx_get(conn_handle);

return ((idx >= 0) ? &contexts[idx] : NULL);
return ((idx >= 0) ? &nus->contexts[idx] : NULL);
}

static uint32_t nus_rx_char_add(struct ble_nus *nus, struct ble_nus_config const *cfg)
Expand Down Expand Up @@ -116,7 +115,7 @@ static void on_connect(struct ble_nus *nus, ble_evt_t const *ble_evt)
};
struct ble_nus_client_context *ctx;

ctx = ble_nus_client_context_get(conn_handle);
ctx = ble_nus_client_context_get(nus, conn_handle);
if (ctx == NULL) {
LOG_ERR("Could not fetch nus context for connection handle %#x", conn_handle);
}
Expand Down Expand Up @@ -152,7 +151,7 @@ static void on_write(struct ble_nus *nus, ble_evt_t const *ble_evt)
};
struct ble_nus_client_context *ctx;

ctx = ble_nus_client_context_get(conn_handle);
ctx = ble_nus_client_context_get(nus, conn_handle);
if (ctx == NULL) {
LOG_ERR("Could not fetch nus context for connection handle %#x", conn_handle);
}
Expand Down Expand Up @@ -202,7 +201,7 @@ static void on_hvx_tx_complete(struct ble_nus *nus, ble_evt_t const *ble_evt)
};
struct ble_nus_client_context *ctx;

ctx = ble_nus_client_context_get(conn_handle);
ctx = ble_nus_client_context_get(nus, conn_handle);
if (ctx == NULL) {
LOG_ERR("Could not fetch nus context for connection handle %#x", conn_handle);
return;
Expand Down Expand Up @@ -317,7 +316,7 @@ int ble_nus_data_send(struct ble_nus *nus, uint8_t *data,
return -ENOENT;
}

ctx = ble_nus_client_context_get(conn_handle);
ctx = ble_nus_client_context_get(nus, conn_handle);
if (ctx == NULL) {
return -ENOENT;
}
Expand Down