1 /** @file
2  *  @brief Bluetooth Coordinated Set Identifier Profile (CSIP) Set Member role.
3  *
4  *  Copyright (c) 2022 Codecoup
5  *  Copyright 2023 NXP
6  *  Copyright (c) 2024 Nordic Semiconductor ASA
7  *
8  *  SPDX-License-Identifier: Apache-2.0
9  */
10 
11 #include <errno.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include <zephyr/autoconf.h>
16 #include <zephyr/bluetooth/audio/cap.h>
17 #include <zephyr/bluetooth/audio/csip.h>
18 #include <zephyr/bluetooth/conn.h>
19 #include <zephyr/kernel.h>
20 #include <zephyr/sys/printk.h>
21 
22 static struct bt_csip_set_member_svc_inst *svc_inst;
23 
csip_lock_changed_cb(struct bt_conn * conn,struct bt_csip_set_member_svc_inst * inst,bool locked)24 static void csip_lock_changed_cb(struct bt_conn *conn,
25 				 struct bt_csip_set_member_svc_inst *inst,
26 				 bool locked)
27 {
28 	printk("Client %p %s the lock\n", conn, locked ? "locked" : "released");
29 }
30 
31 static struct bt_csip_set_member_cb csip_cb = {
32 	.lock_changed = csip_lock_changed_cb,
33 };
34 
csip_set_member_init(void)35 int csip_set_member_init(void)
36 {
37 	struct bt_csip_set_member_register_param param = {
38 		.set_size = 2,
39 		.rank = CONFIG_TMAP_PERIPHERAL_SET_RANK,
40 		.lockable = false,
41 		.cb = &csip_cb,
42 	};
43 
44 	return bt_cap_acceptor_register(&param, &svc_inst);
45 }
46 
csip_generate_rsi(uint8_t * rsi)47 int csip_generate_rsi(uint8_t *rsi)
48 {
49 	int err;
50 
51 	if (svc_inst == NULL) {
52 		return -ENODEV;
53 	}
54 
55 	err = bt_csip_set_member_generate_rsi(svc_inst, rsi);
56 	if (err) {
57 		printk("Failed to generate RSI (err %d)\n", err);
58 		return err;
59 	}
60 
61 	return 0;
62 }
63