Skip to content

Commit 60c8075

Browse files
lib: bluetooth: ble_conn_params: add conn param update request
Add BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST to ble_conn_params library. Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
1 parent 4ced319 commit 60c8075

7 files changed

Lines changed: 63 additions & 22 deletions

File tree

doc/nrf-bm/release_notes/release_notes_changelog.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ Libraries
7373

7474
* :ref:`lib_ble_conn_params`:
7575

76-
* Added support for selecting more than one PHY mode (1M, 2M, and Coded) when setting the PHY mode preference with Kconfig.
76+
* Added:
77+
78+
* Support for selecting more than one PHY mode (1M, 2M, and Coded) when setting the PHY mode preference with Kconfig.
79+
* Support for the :c:macro:`BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST` SoftDevice event.
80+
7781
* Updated the :c:func:`ble_conn_params_phy_radio_mode_set` function to return :c:macro:`NRF_ERROR_INVALID_PARAM` if the ``phy_pref`` parameter contains PHY modes not supported by the SoftDevice.
7882

7983
* Fixed:
@@ -88,6 +92,7 @@ Bluetooth LE Services
8892

8993
* Changed :c:member:`ble_scan_filter_data.addr_filter.addr` and :c:member:`ble_scan_filter_data.name_filter.name` to ``const`` in the :c:struct:`ble_scan_filter_data` structure.
9094

95+
9196
Libraries for NFC
9297
-----------------
9398

lib/bluetooth/ble_conn_params/conn_param.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ static void on_conn_params_update(uint16_t conn_handle, int idx,
144144
}
145145
}
146146

147+
#if defined(CONFIG_SOFTDEVICE_CENTRAL)
148+
static void on_conn_params_update_request(uint16_t conn_handle, int idx,
149+
const ble_gap_evt_conn_param_update_request_t *evt)
150+
{
151+
uint32_t nrf_err;
152+
153+
nrf_err = sd_ble_gap_conn_param_update(conn_handle, &links[idx].ppcp);
154+
if (nrf_err) {
155+
LOG_ERR("Failed to update connection params, nrf_error %#x", nrf_err);
156+
}
157+
}
158+
#endif /* CONFIG_SOFTDEVICE_CENTRAL */
159+
147160
static void on_ble_evt(const ble_evt_t *evt, void *ctx)
148161
{
149162
const uint16_t conn_handle = evt->evt.common_evt.conn_handle;
@@ -163,7 +176,12 @@ static void on_ble_evt(const ble_evt_t *evt, void *ctx)
163176
case BLE_GAP_EVT_CONN_PARAM_UPDATE:
164177
on_conn_params_update(conn_handle, idx, &evt->evt.gap_evt.params.conn_param_update);
165178
break;
166-
179+
#if defined(CONFIG_SOFTDEVICE_CENTRAL)
180+
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
181+
on_conn_params_update_request(conn_handle, idx,
182+
&evt->evt.gap_evt.params.conn_param_update_request);
183+
break;
184+
#endif /* CONFIG_SOFTDEVICE_CENTRAL */
167185
default:
168186
/* Ignore */
169187
break;

samples/bluetooth/ble_hrs_central/src/main.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,6 @@ static void on_ble_evt(const ble_evt_t *ble_evt, void *ctx)
154154
}
155155
break;
156156

157-
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
158-
LOG_INF("ble gap event connection parameter update request");
159-
nrf_err = sd_ble_gap_conn_param_update(
160-
gap_evt->conn_handle,
161-
&gap_evt->params.conn_param_update_request.conn_params);
162-
if (nrf_err) {
163-
LOG_ERR("Failed to update connection params, nrf_error %#x", nrf_err);
164-
}
165-
break;
166-
167157
case BLE_GATTC_EVT_TIMEOUT:
168158
LOG_INF("GATT Client Timeout");
169159
nrf_err = sd_ble_gap_disconnect(ble_evt->evt.gattc_evt.conn_handle,

samples/bluetooth/ble_nus_central/src/main.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,6 @@ static void on_ble_evt(ble_evt_t const *ble_evt, void *context)
215215
LOG_ERR("gap_sec_params_reply failed, nrf_error %#x", nrf_err);
216216
}
217217
break;
218-
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
219-
/** Accepting parameters requested by peer. */
220-
nrf_err = sd_ble_gap_conn_param_update(
221-
gap_evt->conn_handle,
222-
&gap_evt->params.conn_param_update_request.conn_params);
223-
if (nrf_err) {
224-
LOG_ERR("gap_conn_param_update failed, nrf_error %#x", nrf_err);
225-
}
226-
break;
227218
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
228219
LOG_DBG("PHY update request");
229220
nrf_err = sd_ble_gap_phy_update(ble_evt->evt.gap_evt.conn_handle, &phys);

tests/unit/lib/bluetooth/ble_conn_params/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
1010

1111
project(unit_test_ble_conn_params)
1212

13-
set(SOFTDEVICE_VARIANT "s115")
13+
set(SOFTDEVICE_VARIANT "s145")
1414
set(SOFTDEVICE_INCLUDE_DIR "${ZEPHYR_NRF_BM_MODULE_DIR}/components/softdevice/nrf54l/\
1515
${SOFTDEVICE_VARIANT}/${SOFTDEVICE_VARIANT}_API/include")
1616

tests/unit/lib/bluetooth/ble_conn_params/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ config NRF_SDH_BLE_GAP_EVENT_LENGTH
1717
config NRF_SDH_BLE_GATT_MAX_MTU_SIZE
1818
default 24
1919

20+
config SOFTDEVICE_CENTRAL
21+
default y
22+
2023
source "Kconfig.zephyr"

tests/unit/lib/bluetooth/ble_conn_params/src/unity_test.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,40 @@ void test_ble_evt_conn_param_update_busy(void)
996996
TEST_ASSERT_EQUAL(CONN_HANDLE, app_evt.conn_handle);
997997
}
998998

999+
void test_ble_evt_conn_param_update_request_accepted(void)
1000+
{
1001+
ble_evt_t ble_evt = {
1002+
.header.evt_id = BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST,
1003+
.evt.gap_evt = {
1004+
.conn_handle = CONN_HANDLE,
1005+
/* Requested conn params are ignored by the central */
1006+
.params.conn_param_update_request.conn_params = {
1007+
.conn_sup_timeout = 0x12,
1008+
.min_conn_interval = 0x13,
1009+
.max_conn_interval = 0x14,
1010+
.slave_latency = 0x15,
1011+
},
1012+
},
1013+
};
1014+
const ble_gap_conn_params_t conn_params_expected = {
1015+
.conn_sup_timeout = CONFIG_BLE_CONN_PARAMS_SUP_TIMEOUT,
1016+
.min_conn_interval = CONFIG_BLE_CONN_PARAMS_MIN_CONN_INTERVAL,
1017+
.max_conn_interval = CONFIG_BLE_CONN_PARAMS_MAX_CONN_INTERVAL,
1018+
.slave_latency = CONFIG_BLE_CONN_PARAMS_PERIPHERAL_LATENCY,
1019+
};
1020+
1021+
/* Calls from BLE observers. */
1022+
__cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(CONN_HANDLE, 0);
1023+
__cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(CONN_HANDLE, 0);
1024+
__cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(CONN_HANDLE, 0);
1025+
__cmock_nrf_sdh_ble_idx_get_ExpectAndReturn(CONN_HANDLE, 0);
1026+
1027+
__cmock_sd_ble_gap_conn_param_update_ExpectWithArrayAndReturn(
1028+
CONN_HANDLE, &conn_params_expected, 1, NRF_SUCCESS);
1029+
1030+
ble_evt_send(&ble_evt);
1031+
}
1032+
9991033
void test_ble_evt_data_length_update(void)
10001034
{
10011035

0 commit comments

Comments
 (0)