1 /* csip.c - CAP Commander specific VOCS 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/vocs.h>
10 
11 static struct bt_vocs {
12 	bool active;
13 	struct bt_conn *conn;
14 	struct bt_vocs_cb *cb;
15 } vocs_clients[CONFIG_BT_MAX_CONN * CONFIG_BT_VOCS_CLIENT_MAX_INSTANCE_COUNT];
16 
bt_vocs_client_conn_get(const struct bt_vocs * vocs,struct bt_conn ** conn)17 int bt_vocs_client_conn_get(const struct bt_vocs *vocs, struct bt_conn **conn)
18 {
19 	*conn = vocs->conn;
20 
21 	return 0;
22 }
23 
bt_vocs_state_set(struct bt_vocs * vocs,int16_t offset)24 int bt_vocs_state_set(struct bt_vocs *vocs, int16_t offset)
25 {
26 	if (vocs != NULL && vocs->cb != NULL && vocs->cb->set_offset != NULL) {
27 		vocs->cb->set_offset(vocs, 0);
28 	}
29 
30 	return 0;
31 }
32 
bt_vocs_client_cb_register(struct bt_vocs * vocs,struct bt_vocs_cb * cb)33 void bt_vocs_client_cb_register(struct bt_vocs *vocs, struct bt_vocs_cb *cb)
34 {
35 	vocs->cb = cb;
36 }
37 
bt_vocs_client_free_instance_get(void)38 struct bt_vocs *bt_vocs_client_free_instance_get(void)
39 {
40 	for (size_t i = 0U; i < ARRAY_SIZE(vocs_clients); i++) {
41 		if (!vocs_clients[i].active) {
42 			vocs_clients[i].active = true;
43 
44 			return &vocs_clients[i];
45 		}
46 	}
47 
48 	return NULL;
49 }
50 
bt_vocs_discover(struct bt_conn * conn,struct bt_vocs * vocs,const struct bt_vocs_discover_param * param)51 int bt_vocs_discover(struct bt_conn *conn, struct bt_vocs *vocs,
52 		     const struct bt_vocs_discover_param *param)
53 {
54 	vocs->conn = conn;
55 
56 	if (vocs != NULL && vocs->cb != NULL && vocs->cb->discover != NULL) {
57 		vocs->cb->discover(vocs, 0);
58 	}
59 
60 	return 0;
61 }
62 
mock_bt_vocs_init(void)63 void mock_bt_vocs_init(void)
64 {
65 }
66 
mock_bt_vocs_cleanup(void)67 void mock_bt_vocs_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(vocs_clients); i++) {
73 		vocs_clients[i].active = false;
74 		vocs_clients[i].conn = NULL;
75 	}
76 }
77