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