1 /* csip.c - CAP Commander specific AICS mocks */
2 
3 /*
4  * Copyright (c) 2023 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <zephyr/bluetooth/audio/aics.h>
10 
11 static struct bt_aics {
12 	bool active;
13 	struct bt_conn *conn;
14 	struct bt_aics_cb *cb;
15 } aics_clients[CONFIG_BT_MAX_CONN * CONFIG_BT_AICS_CLIENT_MAX_INSTANCE_COUNT];
16 
bt_aics_client_conn_get(const struct bt_aics * aics,struct bt_conn ** conn)17 int bt_aics_client_conn_get(const struct bt_aics *aics, struct bt_conn **conn)
18 {
19 	*conn = aics->conn;
20 
21 	return 0;
22 }
23 
bt_aics_gain_set(struct bt_aics * aics,int8_t gain)24 int bt_aics_gain_set(struct bt_aics *aics, int8_t gain)
25 {
26 	if (aics != NULL && aics->cb != NULL && aics->cb->set_gain != NULL) {
27 		aics->cb->set_gain(aics, 0);
28 	}
29 
30 	return 0;
31 }
32 
bt_aics_client_cb_register(struct bt_aics * aics,struct bt_aics_cb * cb)33 void bt_aics_client_cb_register(struct bt_aics *aics, struct bt_aics_cb *cb)
34 {
35 	aics->cb = cb;
36 }
37 
bt_aics_client_free_instance_get(void)38 struct bt_aics *bt_aics_client_free_instance_get(void)
39 {
40 	for (size_t i = 0U; i < ARRAY_SIZE(aics_clients); i++) {
41 		if (!aics_clients[i].active) {
42 			aics_clients[i].active = true;
43 
44 			return &aics_clients[i];
45 		}
46 	}
47 
48 	return NULL;
49 }
50 
bt_aics_discover(struct bt_conn * conn,struct bt_aics * aics,const struct bt_aics_discover_param * param)51 int bt_aics_discover(struct bt_conn *conn, struct bt_aics *aics,
52 		     const struct bt_aics_discover_param *param)
53 {
54 	aics->conn = conn;
55 
56 	if (aics != NULL && aics->cb != NULL && aics->cb->discover != NULL) {
57 		aics->cb->discover(aics, 0);
58 	}
59 
60 	return 0;
61 }
62 
mock_bt_aics_init(void)63 void mock_bt_aics_init(void)
64 {
65 }
66 
mock_bt_aics_cleanup(void)67 void mock_bt_aics_cleanup(void)
68 {
69 	/* Reset everything but the callbacks, as they will not be registered again between each
70 	 * test
71 	 */
72 	for (size_t i = 0U; i < ARRAY_SIZE(aics_clients); i++) {
73 		aics_clients[i].active = false;
74 		aics_clients[i].conn = NULL;
75 	}
76 }
77