Commit ebd17690 authored by Aleksander Wasaznik's avatar Aleksander Wasaznik Committed by Carles Cufi
Browse files

Bluetooth: testlib: add `bt_testlib_disconnect`

This is a convenience function.

Signed-off-by: default avatarAleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
parent 89c94918
Loading
Loading
Loading
Loading
+1 −0
Changes for tests/bluetooth/common/testlib/CMakeLists.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ target_sources(testlib PRIVATE
  src/conn_ref.c
  src/conn_wait.c
  src/connect.c
  src/disconnect.c
  src/scan.c
)

+18 −0
Changes for tests/bluetooth/common/testlib/include/testlib/conn.h: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -42,6 +42,24 @@
 */
int bt_testlib_connect(const bt_addr_le_t *peer, struct bt_conn **connp);

/**
 * @brief Disconnect, wait and dispose of reference.
 *
 * The disconnect reason for a normal disconnect should be @ref
 * BT_HCI_ERR_REMOTE_USER_TERM_CONN.
 *
 * The following disconnect reasons are allowed:
 *
 *  - @ref BT_HCI_ERR_AUTH_FAIL
 *  - @ref BT_HCI_ERR_REMOTE_USER_TERM_CONN
 *  - @ref BT_HCI_ERR_REMOTE_LOW_RESOURCES
 *  - @ref BT_HCI_ERR_REMOTE_POWER_OFF
 *  - @ref BT_HCI_ERR_UNSUPP_REMOTE_FEATURE
 *  - @ref BT_HCI_ERR_PAIRING_NOT_SUPPORTED
 *  - @ref BT_HCI_ERR_UNACCEPT_CONN_PARAM
 */
int bt_testlib_disconnect(struct bt_conn **connp, uint8_t reason);

/**
 * @brief Wait for connected state
 *
+29 −0
Changes for tests/bluetooth/common/testlib/src/disconnect.c: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
/* Copyright (c) 2024 Nordic Semiconductor ASA
 * SPDX-License-Identifier: Apache-2.0
 */

#include "zephyr/sys/__assert.h"
#include <stdint.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

#include <testlib/conn.h>


int bt_testlib_disconnect(struct bt_conn **connp, uint8_t reason)
{
	int err;

	__ASSERT_NO_MSG(connp);
	__ASSERT_NO_MSG(*connp);

	err = bt_conn_disconnect(*connp, BT_HCI_ERR_REMOTE_USER_TERM_CONN);

	if (!err) {
		bt_testlib_wait_disconnected(*connp);
		bt_testlib_conn_unref(connp);
	}

	return err;
}