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 <stdbool.h>
11 #include <stddef.h>
12 #include <stdint.h>
13 
14 #include <zephyr/bluetooth/addr.h>
15 #include <zephyr/bluetooth/conn.h>
16 #include <zephyr/fff.h>
17 #include <zephyr/sys/iterable_sections.h>
18 
19 #include "conn.h"
20 
21 DEFINE_FAKE_VOID_FUNC(bt_conn_foreach, enum bt_conn_type, bt_conn_foreach_cb, void *);
22 DEFINE_FAKE_VALUE_FUNC(const bt_addr_le_t *, bt_conn_get_dst, const struct bt_conn *);
23 DEFINE_FAKE_VOID_FUNC(bt_foreach_bond, uint8_t, bt_foreach_bond_cb, void *);
24 
25 static struct bt_conn_auth_info_cb *bt_auth_info_cb;
26 
bt_conn_index(const struct bt_conn * conn)27 uint8_t bt_conn_index(const struct bt_conn *conn)
28 {
29 	return conn->index;
30 }
31 
bt_conn_get_info(const struct bt_conn * conn,struct bt_conn_info * info)32 int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info)
33 {
34 	*info = conn->info;
35 
36 	return 0;
37 }
38 
bt_conn_ref(struct bt_conn * conn)39 struct bt_conn *bt_conn_ref(struct bt_conn *conn)
40 {
41 	return conn;
42 }
43 
bt_conn_unref(struct bt_conn * conn)44 void bt_conn_unref(struct bt_conn *conn)
45 {
46 }
47 
bt_conn_auth_info_cb_register(struct bt_conn_auth_info_cb * cb)48 int bt_conn_auth_info_cb_register(struct bt_conn_auth_info_cb *cb)
49 {
50 	if (cb == NULL) {
51 		return -EINVAL;
52 	}
53 
54 	if (bt_auth_info_cb != NULL) {
55 		return -EALREADY;
56 	}
57 
58 	bt_auth_info_cb = cb;
59 
60 	return 0;
61 }
62 
mock_bt_conn_connected(struct bt_conn * conn,uint8_t err)63 void mock_bt_conn_connected(struct bt_conn *conn, uint8_t err)
64 {
65 	STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
66 		if (cb->connected) {
67 			cb->connected(conn, err);
68 		}
69 	}
70 }
71 
mock_bt_conn_disconnected(struct bt_conn * conn,uint8_t err)72 void mock_bt_conn_disconnected(struct bt_conn *conn, uint8_t err)
73 {
74 	STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
75 		if (cb->disconnected) {
76 			cb->disconnected(conn, err);
77 		}
78 	}
79 }
80 
bt_conn_is_type(const struct bt_conn * conn,enum bt_conn_type type)81 bool bt_conn_is_type(const struct bt_conn *conn, enum bt_conn_type type)
82 {
83 	return true;
84 }
85