Skip to content

Commit 5b38093

Browse files
bluetooth: services: nus: Move context to nus structure
Move context to NUS structure. Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
1 parent e0551d6 commit 5b38093

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ Libraries
118118
* All instances of ``pm_failure_evt_t`` to struct :c:struct:`pm_failure_evt` and removed the ``pm_failure_evt_t`` type.
119119
* All instances of ``pm_evt_t`` to struct :c:struct:`pm_evt` and removed the ``pm_evt_t`` type.
120120

121+
* :ref:`lib_ble_service_nus` service:
122+
123+
* Fixed an issue where the client context was shared between all instances.
124+
121125
Samples
122126
=======
123127

include/bm/bluetooth/services/ble_nus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct ble_nus {
149149
/** Handles related to the RX characteristic (as provided by the SoftDevice). */
150150
ble_gatts_char_handles_t rx_handles;
151151
/** Link context with handles of all current connections and its context. */
152-
struct ble_nus_ctx *const ctx;
152+
struct ble_nus_client_context contexts[CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT];
153153
/** Event handler to be called for handling received data. */
154154
ble_nus_evt_handler_t evt_handler;
155155
};

subsys/bluetooth/services/ble_nus/nus.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414

1515
LOG_MODULE_REGISTER(ble_nus, CONFIG_BLE_NUS_LOG_LEVEL);
1616

17-
static struct ble_nus_client_context contexts[CONFIG_NRF_SDH_BLE_TOTAL_LINK_COUNT];
18-
19-
static struct ble_nus_client_context *ble_nus_client_context_get(uint16_t conn_handle)
17+
static struct ble_nus_client_context *ble_nus_client_context_get(struct ble_nus *nus,
18+
uint16_t conn_handle)
2019
{
2120
const int idx = nrf_sdh_ble_idx_get(conn_handle);
2221

23-
return ((idx >= 0) ? &contexts[idx] : NULL);
22+
return ((idx >= 0) ? &nus->contexts[idx] : NULL);
2423
}
2524

2625
static uint32_t nus_rx_char_add(struct ble_nus *nus, struct ble_nus_config const *cfg)
@@ -116,7 +115,7 @@ static void on_connect(struct ble_nus *nus, ble_evt_t const *ble_evt)
116115
};
117116
struct ble_nus_client_context *ctx;
118117

119-
ctx = ble_nus_client_context_get(conn_handle);
118+
ctx = ble_nus_client_context_get(nus, conn_handle);
120119
if (ctx == NULL) {
121120
LOG_ERR("Could not fetch nus context for connection handle %#x", conn_handle);
122121
}
@@ -152,7 +151,7 @@ static void on_write(struct ble_nus *nus, ble_evt_t const *ble_evt)
152151
};
153152
struct ble_nus_client_context *ctx;
154153

155-
ctx = ble_nus_client_context_get(conn_handle);
154+
ctx = ble_nus_client_context_get(nus, conn_handle);
156155
if (ctx == NULL) {
157156
LOG_ERR("Could not fetch nus context for connection handle %#x", conn_handle);
158157
}
@@ -202,7 +201,7 @@ static void on_hvx_tx_complete(struct ble_nus *nus, ble_evt_t const *ble_evt)
202201
};
203202
struct ble_nus_client_context *ctx;
204203

205-
ctx = ble_nus_client_context_get(conn_handle);
204+
ctx = ble_nus_client_context_get(nus, conn_handle);
206205
if (ctx == NULL) {
207206
LOG_ERR("Could not fetch nus context for connection handle %#x", conn_handle);
208207
return;
@@ -317,7 +316,7 @@ int ble_nus_data_send(struct ble_nus *nus, uint8_t *data,
317316
return -ENOENT;
318317
}
319318

320-
ctx = ble_nus_client_context_get(conn_handle);
319+
ctx = ble_nus_client_context_get(nus, conn_handle);
321320
if (ctx == NULL) {
322321
return -ENOENT;
323322
}

0 commit comments

Comments
 (0)