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