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 #include <errno.h>
9 #include <stddef.h>
10 #include <stdint.h>
11
12 #include <zephyr/autoconf.h>
13 #include <zephyr/bluetooth/audio/cap.h>
14 #include <zephyr/bluetooth/audio/csip.h>
15 #include <zephyr/bluetooth/conn.h>
16 #include <zephyr/kernel.h>
17 #include <zephyr/sys/printk.h>
18
19 #define CSIP_SIRK_DEBUG { 0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce, \
20 0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 }
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
sirk_read_req_cb(struct bt_conn * conn,struct bt_csip_set_member_svc_inst * inst)31 static uint8_t sirk_read_req_cb(struct bt_conn *conn,
32 struct bt_csip_set_member_svc_inst *inst)
33 {
34 return BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT;
35 }
36
37 static struct bt_csip_set_member_cb csip_cb = {
38 .lock_changed = csip_lock_changed_cb,
39 .sirk_read_req = sirk_read_req_cb,
40 };
41
csip_set_member_init(void)42 int csip_set_member_init(void)
43 {
44 struct bt_csip_set_member_register_param param = {
45 .set_size = 2,
46 .rank = CONFIG_HAP_HA_SET_RANK,
47 .lockable = false,
48 .sirk = CSIP_SIRK_DEBUG,
49 .cb = &csip_cb,
50 };
51
52 return bt_cap_acceptor_register(¶m, &svc_inst);
53 }
54
csip_generate_rsi(uint8_t * rsi)55 int csip_generate_rsi(uint8_t *rsi)
56 {
57 int err;
58
59 if (svc_inst == NULL) {
60 return -ENODEV;
61 }
62
63 err = bt_csip_set_member_generate_rsi(svc_inst, rsi);
64 if (err) {
65 printk("Failed to generate RSI (err %d)\n", err);
66 return err;
67 }
68
69 return 0;
70 }
71