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 #include <stdbool.h>
9 #include <stdint.h>
10 #include <stddef.h>
11
12 #include <zephyr/bluetooth/audio/aics.h>
13 #include <zephyr/bluetooth/conn.h>
14 #include <zephyr/sys/util.h>
15
16 static struct bt_aics {
17 bool active;
18 struct bt_conn *conn;
19 struct bt_aics_cb *cb;
20 } aics_clients[CONFIG_BT_MAX_CONN * CONFIG_BT_AICS_CLIENT_MAX_INSTANCE_COUNT];
21
bt_aics_client_conn_get(const struct bt_aics * aics,struct bt_conn ** conn)22 int bt_aics_client_conn_get(const struct bt_aics *aics, struct bt_conn **conn)
23 {
24 *conn = aics->conn;
25
26 return 0;
27 }
28
bt_aics_gain_set(struct bt_aics * aics,int8_t gain)29 int bt_aics_gain_set(struct bt_aics *aics, int8_t gain)
30 {
31 if (aics != NULL && aics->cb != NULL && aics->cb->set_gain != NULL) {
32 aics->cb->set_gain(aics, 0);
33 }
34
35 return 0;
36 }
37
bt_aics_client_cb_register(struct bt_aics * aics,struct bt_aics_cb * cb)38 void bt_aics_client_cb_register(struct bt_aics *aics, struct bt_aics_cb *cb)
39 {
40 aics->cb = cb;
41 }
42
bt_aics_client_free_instance_get(void)43 struct bt_aics *bt_aics_client_free_instance_get(void)
44 {
45 for (size_t i = 0U; i < ARRAY_SIZE(aics_clients); i++) {
46 if (!aics_clients[i].active) {
47 aics_clients[i].active = true;
48
49 return &aics_clients[i];
50 }
51 }
52
53 return NULL;
54 }
55
bt_aics_discover(struct bt_conn * conn,struct bt_aics * aics,const struct bt_aics_discover_param * param)56 int bt_aics_discover(struct bt_conn *conn, struct bt_aics *aics,
57 const struct bt_aics_discover_param *param)
58 {
59
60 if (aics == NULL) {
61 return -EINVAL;
62 }
63
64 aics->conn = conn;
65
66 if (aics->cb != NULL && aics->cb->discover != NULL) {
67 aics->cb->discover(aics, 0);
68 }
69
70 return 0;
71 }
72
mock_bt_aics_init(void)73 void mock_bt_aics_init(void)
74 {
75 }
76
mock_bt_aics_cleanup(void)77 void mock_bt_aics_cleanup(void)
78 {
79 /* Reset everything but the callbacks, as they will not be registered again between each
80 * test
81 */
82 for (size_t i = 0U; i < ARRAY_SIZE(aics_clients); i++) {
83 aics_clients[i].active = false;
84 aics_clients[i].conn = NULL;
85 }
86 }
87