1 /*
2 * Copyright (c) 2023 Codecoup
3 * Copyright (c) 2024-2025 Nordic Semiconductor ASA
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7 #include <stdint.h>
8
9 #include <errno.h>
10 #include <stddef.h>
11 #include <stdint.h>
12
13 #include <zephyr/bluetooth/addr.h>
14 #include <zephyr/bluetooth/conn.h>
15 #include <zephyr/fff.h>
16 #include <zephyr/sys/iterable_sections.h>
17
18 #include "conn.h"
19
20 DEFINE_FAKE_VOID_FUNC(bt_conn_foreach, enum bt_conn_type, bt_conn_foreach_cb, void *);
21 DEFINE_FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_conn_get_dst, const struct bt_conn *);
22 DEFINE_FAKE_VOID_FUNC(bt_foreach_bond, uint8_t, bt_foreach_bond_cb, void *);
23
24 static struct bt_conn_auth_info_cb *bt_auth_info_cb;
25
bt_conn_index(const struct bt_conn * conn)26 uint8_t bt_conn_index(const struct bt_conn *conn)
27 {
28 return conn->index;
29 }
30
bt_conn_get_info(const struct bt_conn * conn,struct bt_conn_info * info)31 int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info)
32 {
33 *info = conn->info;
34
35 return 0;
36 }
37
bt_conn_ref(struct bt_conn * conn)38 struct bt_conn *bt_conn_ref(struct bt_conn *conn)
39 {
40 return conn;
41 }
42
bt_conn_unref(struct bt_conn * conn)43 void bt_conn_unref(struct bt_conn *conn)
44 {
45 }
46
bt_conn_auth_info_cb_register(struct bt_conn_auth_info_cb * cb)47 int bt_conn_auth_info_cb_register(struct bt_conn_auth_info_cb *cb)
48 {
49 if (cb == NULL) {
50 return -EINVAL;
51 }
52
53 if (bt_auth_info_cb != NULL) {
54 return -EALREADY;
55 }
56
57 bt_auth_info_cb = cb;
58
59 return 0;
60 }
61
mock_bt_conn_connected(struct bt_conn * conn,uint8_t err)62 void mock_bt_conn_connected(struct bt_conn *conn, uint8_t err)
63 {
64 STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
65 if (cb->connected) {
66 cb->connected(conn, err);
67 }
68 }
69 }
70
mock_bt_conn_disconnected(struct bt_conn * conn,uint8_t err)71 void mock_bt_conn_disconnected(struct bt_conn *conn, uint8_t err)
72 {
73 STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
74 if (cb->disconnected) {
75 cb->disconnected(conn, err);
76 }
77 }
78 }
79