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 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <zephyr/autoconf.h>
12 #include <zephyr/bluetooth/audio/vocs.h>
13 #include <zephyr/bluetooth/conn.h>
14 #include <zephyr/sys/util.h>
15 
16 static struct bt_vocs {
17 	bool active;
18 	struct bt_conn *conn;
19 	struct bt_vocs_cb *cb;
20 } vocs_clients[CONFIG_BT_MAX_CONN * CONFIG_BT_VOCS_CLIENT_MAX_INSTANCE_COUNT];
21 
bt_vocs_client_conn_get(const struct bt_vocs * vocs,struct bt_conn ** conn)22 int bt_vocs_client_conn_get(const struct bt_vocs *vocs, struct bt_conn **conn)
23 {
24 	*conn = vocs->conn;
25 
26 	return 0;
27 }
28 
bt_vocs_state_set(struct bt_vocs * vocs,int16_t offset)29 int bt_vocs_state_set(struct bt_vocs *vocs, int16_t offset)
30 {
31 	if (vocs != NULL && vocs->cb != NULL && vocs->cb->set_offset != NULL) {
32 		vocs->cb->set_offset(vocs, 0);
33 	}
34 
35 	return 0;
36 }
37 
bt_vocs_client_cb_register(struct bt_vocs * vocs,struct bt_vocs_cb * cb)38 void bt_vocs_client_cb_register(struct bt_vocs *vocs, struct bt_vocs_cb *cb)
39 {
40 	vocs->cb = cb;
41 }
42 
bt_vocs_client_free_instance_get(void)43 struct bt_vocs *bt_vocs_client_free_instance_get(void)
44 {
45 	for (size_t i = 0U; i < ARRAY_SIZE(vocs_clients); i++) {
46 		if (!vocs_clients[i].active) {
47 			vocs_clients[i].active = true;
48 
49 			return &vocs_clients[i];
50 		}
51 	}
52 
53 	return NULL;
54 }
55 
bt_vocs_discover(struct bt_conn * conn,struct bt_vocs * vocs,const struct bt_vocs_discover_param * param)56 int bt_vocs_discover(struct bt_conn *conn, struct bt_vocs *vocs,
57 		     const struct bt_vocs_discover_param *param)
58 {
59 	vocs->conn = conn;
60 
61 	if (vocs != NULL && vocs->cb != NULL && vocs->cb->discover != NULL) {
62 		vocs->cb->discover(vocs, 0);
63 	}
64 
65 	return 0;
66 }
67 
mock_bt_vocs_init(void)68 void mock_bt_vocs_init(void)
69 {
70 }
71 
mock_bt_vocs_cleanup(void)72 void mock_bt_vocs_cleanup(void)
73 {
74 	/* Reset everything but the callbacks, as they will not be registered again between each
75 	 * test
76 	 */
77 	for (size_t i = 0U; i < ARRAY_SIZE(vocs_clients); i++) {
78 		vocs_clients[i].active = false;
79 		vocs_clients[i].conn = NULL;
80 	}
81 }
82