Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6390753rwb; Tue, 22 Nov 2022 12:41:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7hItfOLDO1D/InC96K+I06vB5adwtQGgbBIgsuYjg9vegoEKTY9d12ZLvFgRkybbxu9kHJ X-Received: by 2002:a17:903:2687:b0:176:d217:7e68 with SMTP id jf7-20020a170903268700b00176d2177e68mr5296497plb.63.1669149662903; Tue, 22 Nov 2022 12:41:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669149662; cv=none; d=google.com; s=arc-20160816; b=B9Kpj3/Z762y45GEmelCXXKZAEgMlBen9Ovui2CnsjGcdu4bhlBuSTWx2Fs6MoqwDR Ub3oqrldeEwodD2VwsNbkhdRWpqz8rakcpJxmrU1EJIBQx7Ftk0oqaqQei2x/pdfcpax JmgkgDzVAhIK6AsemYLeaX0AXYjb+L5to0xY6vD2Sr2cnp8P+YMjxxVF9GonQ/HQQwBB Ui6LJDWIS5FlAxO55S8kJOVqaq7AufMqtmDQrPQgW2JIYfADw3f/jvHiErGPjy3BC5Jt zJZnRI3NYFedWnsbfY1NIDiQiEP0gL23uGUzkA8HhvijmOYL1L84VS/yLV6CSxTKdtGs W8jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=MUFS3NSjmtD2Cxa6jzaipPFwYorzYIBWWGYQciT3mnA=; b=cxVWG6l3xAW/nMcz5YLtAWLXBOXSHszky6QQAfOaumS/nnPEhBfNAaPFDHPK48j7+s FM56TRv3mDR265rJ2kuUcNRUCx+uT47aF7EBCGxBKngXKbPiOkqN9zwvhGhVxudnCN/Z cBZM1m4CJ2WnwUYMgKp8gTwKrdZv1joJVVNie/X7rzCSkjVkDXnia2kNtgeuASFJgNM7 csV2ylh/JdtDXmZbLnGQxegQ6rhOabbsGUB9HZBGwvWb1DXgU//abMIIWT/y4/Ci4+rk ZxnqllgjvtxGKusr2OMewZCHQc+2lyw/air76gKVzH/g3GjkIQt20Vq/ZwHCVrawX7pm 3AuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pzyBE41W; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k189-20020a6384c6000000b00477b64d8e5csi733233pgd.160.2022.11.22.12.40.49; Tue, 22 Nov 2022 12:41:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pzyBE41W; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234788AbiKVUho (ORCPT + 99 others); Tue, 22 Nov 2022 15:37:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233908AbiKVUhm (ORCPT ); Tue, 22 Nov 2022 15:37:42 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B05621BA for ; Tue, 22 Nov 2022 12:37:40 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id be13so25295960lfb.4 for ; Tue, 22 Nov 2022 12:37:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MUFS3NSjmtD2Cxa6jzaipPFwYorzYIBWWGYQciT3mnA=; b=pzyBE41WZG7HiA5QXtA9cE6d5oVyMXXfdpKStVMun6PCWUwKTU/kwTQ/NFSG/1B2nX g+lBmZlB5z1jnHOn02XlMZPiwaJkO1N2juS9wrdbLpfKjuj0usGrmD+z/T9RCKudn80i G5pKoQZPjjZRU4Bu6Sp7UovVz6BtGetxJfLzBIZJ4mR9Zy8Q9dWPRND/stDpTBpLIsvY gzF2em5F2qR8orKT0ws1zd1AtdEL0arQUSJ2NzvHMNGcTR+H6niuIalrDU1l4ahhTvso w4oeNImjXREYukhDXLvMp87gLdeEsb/WlMgKAD1bBlfV4yua7KjY6Vs6ylayoePFD0/U j1iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MUFS3NSjmtD2Cxa6jzaipPFwYorzYIBWWGYQciT3mnA=; b=VG7evZiqHi2YQUwYbDVcabm+fei1TkyBXdmNW9KoRnq/nRg7J3Vs36nc0wMOPo4lrc jH6GWj6AhFw018WHo9SEGKZaxHxax/XOGBC1oa7e0qoOCQmux9U0QVyl+mfUcn/cbAWf Vw3xmxDU8Nf+EsVZlonCZIfyWvFMMuohUmOvbRw79i8qf7/WwBAU2ecXtheUruCE7Zn2 4af1IHqeg6EzBT/iYKQ6d9DM+Tq0LbvBwj0E+OMy3VVOlsPQPi41A0Knr4+9SyYy4FbJ pyuQb+ibek/7jhnm+gTw1Pa9Wva/pIdE4fxJyhVX09sboIgis2clVn707C4oOyxvff2J Z6OA== X-Gm-Message-State: ANoB5pm08/5g3UnpkkEJguum0LEFsYIG/APN1z5T0i14ascNSQXrIoBo tZgB/Kzl98o9V3JPC78E3JgcEKa3oMaLAGwcGUYz2sJk X-Received: by 2002:a05:6512:25a3:b0:4b4:bc44:2b40 with SMTP id bf35-20020a05651225a300b004b4bc442b40mr3396771lfb.564.1669149458493; Tue, 22 Nov 2022 12:37:38 -0800 (PST) MIME-Version: 1.0 References: <20221122101232.45320-1-sathish.narasimman@intel.com> <20221122101232.45320-5-sathish.narasimman@intel.com> In-Reply-To: <20221122101232.45320-5-sathish.narasimman@intel.com> From: Luiz Augusto von Dentz Date: Tue, 22 Nov 2022 12:37:26 -0800 Message-ID: Subject: Re: [PATCH BlueZ v3 4/7] shared/csip: Add initial code for handling CSIP To: Sathish Narasimman Cc: linux-bluetooth@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Sathish, On Tue, Nov 22, 2022 at 2:16 AM Sathish Narasimman wrote: > > This adds initial code for Coordinated Set Identification Profile. > --- > Makefile.am | 1 + > src/shared/csip.c | 554 ++++++++++++++++++++++++++++++++++++++++++++++ > src/shared/csip.h | 44 ++++ > 3 files changed, 599 insertions(+) > create mode 100644 src/shared/csip.c > create mode 100644 src/shared/csip.h > > diff --git a/Makefile.am b/Makefile.am > index aa3a5e053cd8..b546a1803dfd 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -233,6 +233,7 @@ shared_sources = src/shared/io.h src/shared/timeout.h \ > src/shared/bap.h src/shared/bap.c src/shared/ascs.h \ > src/shared/mcs.h src/shared/mcp.h src/shared/mcp.c \ > src/shared/vcp.c src/shared/vcp.h \ > + src/shared/csip.c src/shared/csip.h \ > src/shared/lc3.h src/shared/tty.h > > if READLINE > diff --git a/src/shared/csip.c b/src/shared/csip.c > new file mode 100644 > index 000000000000..98e42d914b16 > --- /dev/null > +++ b/src/shared/csip.c > @@ -0,0 +1,554 @@ > +// SPDX-License-Identifier: LGPL-2.1-or-later > +/* > + * > + * BlueZ - Bluetooth protocol stack for Linux > + * > + * Copyright (C) 2022 Intel Corporation. All rights reserved. > + * > + */ > + > +#define _GNU_SOURCE > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +#include "lib/bluetooth.h" > +#include "lib/uuid.h" > + > +#include "src/shared/queue.h" > +#include "src/shared/util.h" > +#include "src/shared/timeout.h" > +#include "src/shared/att.h" > +#include "src/shared/gatt-db.h" > +#include "src/shared/gatt-server.h" > +#include "src/shared/gatt-client.h" > +#include "src/shared/csip.h" > +#include "src/btd.h" > + > +#define DBG(_csip, fmt, arg...) \ > + csip_debug(_csip, "%s:%s() " fmt, __FILE__, __func__, ## arg) > + > +/* SIRK is now hardcoded in the code. This can be moved > + * to a configuration file. Since the code is to validate > + * the CSIP use case of set member > + */ > +#define SIRK "761FAE703ED681F0C50B34155B6434FB" > +#define CSIS_SIZE 0x02 > +#define CSIS_LOCK 0x01 > +#define CSIS_RANK 0x01 > +#define CSIS_PLAINTEXT 0x01 > +#define CSIS_ENC 0x02 > + > +struct bt_csip_db { > + struct gatt_db *db; > + struct bt_csis *csis; > +}; > + > +struct csis_sirk { > + uint8_t type; > + uint8_t val[16]; > +} __packed; > + > +struct bt_csis { > + struct bt_csip_db *cdb; > + struct csis_sirk *sirk; > + uint8_t cs_size; > + uint8_t cs_lock; > + uint8_t cs_rank; > + struct gatt_db_attribute *service; > + struct gatt_db_attribute *csirk; > + struct gatt_db_attribute *csize; > + struct gatt_db_attribute *cslock; > + struct gatt_db_attribute *cslock_ccc; > + struct gatt_db_attribute *crank; > +}; > + > +struct bt_csip_cb { > + unsigned int id; > + bt_csip_func_t attached; > + bt_csip_func_t detached; > + void *user_data; > +}; > + > +struct bt_csip { > + int ref_count; > + struct bt_csip_db *ldb; > + struct bt_csip_db *rdb; > + struct bt_gatt_client *client; > + struct bt_att *att; > + > + struct queue *pending; > + > + bt_csip_debug_func_t debug_func; > + bt_csip_destroy_func_t debug_destroy; > + void *debug_data; > + void *user_data; > +}; > + > +static struct queue *csip_db; > +static struct queue *csip_cbs; > +static struct queue *sessions; > + > +static void csip_detached(void *data, void *user_data) > +{ > + struct bt_csip_cb *cb = data; > + struct bt_csip *csip = user_data; > + > + cb->detached(csip, cb->user_data); > +} > + > +void bt_csip_detach(struct bt_csip *csip) > +{ > + if (!queue_remove(sessions, csip)) > + return; > + > + bt_gatt_client_unref(csip->client); > + csip->client = NULL; > + > + queue_foreach(csip_cbs, csip_detached, csip); > +} > + > +static void csip_db_free(void *data) > +{ > + struct bt_csip_db *cdb = data; > + > + if (!cdb) > + return; > + > + gatt_db_unref(cdb->db); > + > + free(cdb->csis); > + free(cdb); > +} > +static void csip_free(void *data) > +{ > + struct bt_csip *csip = data; > + > + bt_csip_detach(csip); > + > + csip_db_free(csip->rdb); > + > + queue_destroy(csip->pending, NULL); > + > + free(csip); > +} > + > +struct bt_att *bt_csip_get_att(struct bt_csip *csip) > +{ > + if (!csip) > + return NULL; > + > + if (csip->att) > + return csip->att; > + > + return bt_gatt_client_get_att(csip->client); > +} > + > +struct bt_csip *bt_csip_ref(struct bt_csip *csip) > +{ > + if (!csip) > + return NULL; > + > + __sync_fetch_and_add(&csip->ref_count, 1); > + > + return csip; > +} > + > +void bt_csip_unref(struct bt_csip *csip) > +{ > + if (!csip) > + return; > + > + if (__sync_sub_and_fetch(&csip->ref_count, 1)) > + return; > + > + csip_free(csip); > +} > + > +static void csip_debug(struct bt_csip *csip, const char *format, ...) > +{ > + va_list ap; > + > + if (!csip || !format || !csip->debug_func) > + return; > + > + va_start(ap, format); > + util_debug_va(csip->debug_func, csip->debug_data, format, ap); > + va_end(ap); > +} > + > +static void csis_sirk_read(struct gatt_db_attribute *attrib, > + unsigned int id, uint16_t offset, > + uint8_t opcode, struct bt_att *att, > + void *user_data) > +{ > + struct bt_csis *csis = user_data; > + struct iovec iov; > + > + iov.iov_base = csis->sirk; > + iov.iov_len = sizeof(struct csis_sirk); > + > + gatt_db_attribute_read_result(attrib, id, 0, iov.iov_base, > + iov.iov_len); > +} > + > +static void csis_size_read(struct gatt_db_attribute *attrib, > + unsigned int id, uint16_t offset, > + uint8_t opcode, struct bt_att *att, > + void *user_data) > +{ > + struct bt_csis *csis = user_data; > + struct iovec iov; > + > + iov.iov_base = &csis->cs_size; > + iov.iov_len = sizeof(csis->cs_size); > + > + gatt_db_attribute_read_result(attrib, id, 0, iov.iov_base, > + iov.iov_len); > +} > + > +static void csis_lock_read_cb(struct gatt_db_attribute *attrib, > + unsigned int id, uint16_t offset, > + uint8_t opcode, struct bt_att *att, > + void *user_data) > +{ > + uint8_t value = CSIS_LOCK; > + > + gatt_db_attribute_read_result(attrib, id, 0, &value, sizeof(value)); > +} > + > +static void csis_lock_write_cb(struct gatt_db_attribute *attrib, > + unsigned int id, uint16_t offset, > + const uint8_t *value, size_t len, > + uint8_t opcode, struct bt_att *att, > + void *user_data) > +{ > + gatt_db_attribute_write_result(attrib, id, 0); > +} > + > +static void csis_rank_read_cb(struct gatt_db_attribute *attrib, > + unsigned int id, uint16_t offset, > + uint8_t opcode, struct bt_att *att, > + void *user_data) > +{ > + uint8_t value = CSIS_RANK; > + > + gatt_db_attribute_read_result(attrib, id, 0, &value, sizeof(value)); > +} > + > +static struct bt_csis *csis_new(struct gatt_db *db) > +{ > + struct bt_csis *csis; > + struct csis_sirk *sirk; > + bt_uuid_t uuid; > + > + /* For Common Audio Service*/ > + struct gatt_db_attribute *service; > + > + if (!db) > + return NULL; > + > + csis = new0(struct bt_csis, 1); > + sirk = new0(struct csis_sirk, 1); > + > + sirk->type = btd_opts.csis_defaults.sirk_type; > + memcpy(sirk->val, btd_opts.csis_defaults.sirk_val, > + sizeof(sirk->val)); > + csis->sirk = sirk; > + csis->cs_size = btd_opts.csis_defaults.cs_size; > + csis->cs_lock = 1; > + csis->cs_rank = btd_opts.csis_defaults.cs_rank; We can't have the shared code depending directly on the daemon code (e.g. btd_opts) since we want this code to be testable via unit testing framework (see unit/test-bap.c), so you probably want to pass these values via function parameter. > + /* Populate DB with CSIS attributes */ > + bt_uuid16_create(&uuid, CSIS_UUID); > + csis->service = gatt_db_add_service(db, &uuid, true, 10); > + > + bt_uuid16_create(&uuid, CS_SIRK); > + csis->csirk = gatt_db_service_add_characteristic(csis->service, > + &uuid, > + BT_ATT_PERM_READ, > + BT_GATT_CHRC_PROP_READ, > + csis_sirk_read, NULL, > + csis); > + > + bt_uuid16_create(&uuid, CS_SIZE); > + csis->csize = gatt_db_service_add_characteristic(csis->service, > + &uuid, > + BT_ATT_PERM_READ, > + BT_GATT_CHRC_PROP_READ, > + csis_size_read, NULL, > + csis); > + > + /* Lock */ > + bt_uuid16_create(&uuid, CS_LOCK); > + csis->cslock = gatt_db_service_add_characteristic(csis->service, &uuid, > + BT_ATT_PERM_READ, > + BT_GATT_CHRC_PROP_READ | > + BT_GATT_CHRC_PROP_WRITE | > + BT_GATT_CHRC_PROP_NOTIFY, > + csis_lock_read_cb, > + csis_lock_write_cb, > + csis); > + > + csis->cslock_ccc = gatt_db_service_add_ccc(csis->service, > + BT_ATT_PERM_READ | BT_ATT_PERM_WRITE); > + > + /* Rank */ > + bt_uuid16_create(&uuid, CS_RANK); > + csis->crank = gatt_db_service_add_characteristic(csis->service, &uuid, > + BT_ATT_PERM_READ, > + BT_GATT_CHRC_PROP_READ, > + csis_rank_read_cb, > + NULL, csis); > + > + /* Add the CAS service */ > + bt_uuid16_create(&uuid, 0x1853); > + service = gatt_db_add_service(db, &uuid, true, 2); > + gatt_db_service_add_included(service, csis->service); > + gatt_db_service_set_active(service, true); > + gatt_db_service_add_included(service, csis->service); > + > + gatt_db_service_set_active(csis->service, true); > + > + return csis; > +} > + > +static struct bt_csip_db *csip_db_new(struct gatt_db *db) > +{ > + struct bt_csip_db *cdb; > + > + if (!db) > + return NULL; > + > + cdb = new0(struct bt_csip_db, 1); > + cdb->db = gatt_db_ref(db); > + > + if (!csip_db) > + csip_db = queue_new(); > + > + cdb->csis = csis_new(db); > + cdb->csis->cdb = cdb; > + > + queue_push_tail(csip_db, cdb); > + > + return cdb; > +} > + > +bool bt_csip_set_user_data(struct bt_csip *csip, void *user_data) > +{ > + if (!csip) > + return false; > + > + csip->user_data = user_data; > + > + return true; > +} > + > +static bool csip_db_match(const void *data, const void *match_data) > +{ > + const struct bt_csip_db *cdb = data; > + const struct gatt_db *db = match_data; > + > + return (cdb->db == db); > +} > + > +static struct bt_csip_db *csip_get_db(struct gatt_db *db) > +{ > + struct bt_csip_db *cdb; > + > + cdb = queue_find(csip_db, csip_db_match, db); > + if (cdb) > + return cdb; > + > + return csip_db_new(db); > +} > + > +void bt_csip_add_db(struct gatt_db *db) > +{ > + csip_db_new(db); > +} > + > +bool bt_csip_set_debug(struct bt_csip *csip, bt_csip_debug_func_t func, > + void *user_data, bt_csip_destroy_func_t destroy) > +{ > + if (!csip) > + return false; > + > + if (csip->debug_destroy) > + csip->debug_destroy(csip->debug_data); > + > + csip->debug_func = func; > + csip->debug_destroy = destroy; > + csip->debug_data = user_data; > + > + return true; > +} > + > +unsigned int bt_csip_register(bt_csip_func_t attached, bt_csip_func_t detached, > + void *user_data) > +{ > + struct bt_csip_cb *cb; > + static unsigned int id; > + > + if (!attached && !detached) > + return 0; > + > + if (!csip_cbs) > + csip_cbs = queue_new(); > + > + cb = new0(struct bt_csip_cb, 1); > + cb->id = ++id ? id : ++id; > + cb->attached = attached; > + cb->detached = detached; > + cb->user_data = user_data; > + > + queue_push_tail(csip_cbs, cb); > + > + return cb->id; > +} > + > +static bool match_id(const void *data, const void *match_data) > +{ > + const struct bt_csip_cb *cb = data; > + unsigned int id = PTR_TO_UINT(match_data); > + > + return (cb->id == id); > +} > + > +bool bt_csip_unregister(unsigned int id) > +{ > + struct bt_csip_cb *cb; > + > + cb = queue_remove_if(csip_cbs, match_id, UINT_TO_PTR(id)); > + if (!cb) > + return false; > + > + free(cb); > + > + return true; > +} > + > +struct bt_csip *bt_csip_new(struct gatt_db *ldb, struct gatt_db *rdb) > +{ > + struct bt_csip *csip; > + struct bt_csip_db *db; > + > + if (!ldb) > + return NULL; > + > + db = csip_get_db(ldb); > + if (!db) > + return NULL; > + > + csip = new0(struct bt_csip, 1); > + csip->ldb = db; > + csip->pending = queue_new(); > + > + if (!rdb) > + goto done; > + > + db = new0(struct bt_csip_db, 1); > + db->db = gatt_db_ref(rdb); > + > + csip->rdb = db; > + > +done: > + bt_csip_ref(csip); > + > + return csip; > +} > + > +static struct bt_csis *csip_get_csis(struct bt_csip *csip) > +{ > + if (!csip) > + return NULL; > + > + if (csip->rdb->csis) > + return csip->rdb->csis; > + > + csip->rdb->csis = new0(struct bt_csis, 1); > + csip->rdb->csis->cdb = csip->rdb; > + > + return csip->rdb->csis; > +} > + > +static void foreach_csis_char(struct gatt_db_attribute *attr, void *user_data) > +{ > + struct bt_csip *csip = user_data; > + uint16_t value_handle; > + bt_uuid_t uuid, uuid_csirk, uuid_csize; > + struct bt_csis *csis; > + > + if (!gatt_db_attribute_get_char_data(attr, NULL, &value_handle, > + NULL, NULL, &uuid)) > + return; > + > + bt_uuid16_create(&uuid_csirk, CS_SIRK); > + bt_uuid16_create(&uuid_csize, CS_SIZE); > + > + if (!bt_uuid_cmp(&uuid, &uuid_csirk)) { > + DBG(csip, "CSIS IRK found: handle 0x%04x", value_handle); > + > + csis = csip_get_csis(csip); > + if (!csis || csis->sirk) > + return; > + > + csis->csirk = attr; > + return; > + } > + > + if (!bt_uuid_cmp(&uuid, &uuid_csize)) { > + DBG(csip, "CSIS SIZE found: handle 0x%04x", value_handle); > + > + csis = csip_get_csis(csip); > + if (!csis) > + return; > + > + csis->csize = attr; > + } > + > +} > +static void foreach_csis_service(struct gatt_db_attribute *attr, > + void *user_data) > +{ > + struct bt_csip *csip = user_data; > + struct bt_csis *csis = csip_get_csis(csip); > + > + csis->service = attr; > + > + gatt_db_service_set_claimed(attr, true); > + > + gatt_db_service_foreach_char(attr, foreach_csis_char, csip); > +} > + > +bool bt_csip_attach(struct bt_csip *csip, struct bt_gatt_client *client) > +{ > + bt_uuid_t uuid; > + > + if (!sessions) > + sessions = queue_new(); > + > + queue_push_tail(sessions, csip); > + > + if (!client) > + return true; > + > + if (csip->client) > + return false; > + > + csip->client = bt_gatt_client_clone(client); > + if (!csip->client) > + return false; > + > + bt_uuid16_create(&uuid, CSIS_UUID); > + gatt_db_foreach_service(csip->ldb->db, &uuid, foreach_csis_service, > + csip); > + > + return true; > +} > + > diff --git a/src/shared/csip.h b/src/shared/csip.h > new file mode 100644 > index 000000000000..bd88ccf3a0b2 > --- /dev/null > +++ b/src/shared/csip.h > @@ -0,0 +1,44 @@ > +/* SPDX-License-Identifier: LGPL-2.1-or-later */ > +/* > + * > + * BlueZ - Bluetooth protocol stack for Linux > + * > + * Copyright (C) 2022 Intel Corporation. All rights reserved. > + * > + */ > + > +#include > +#include > + > +#include "src/shared/io.h" > + > +#ifndef __packed > +#define __packed __attribute__((packed)) > +#endif > + > +struct bt_csip; > + > +typedef void (*bt_csip_destroy_func_t)(void *user_data); > +typedef void (*bt_csip_debug_func_t)(const char *str, void *user_data); > +typedef void (*bt_csip_func_t)(struct bt_csip *csip, void *user_data); > +struct bt_csip *bt_csip_ref(struct bt_csip *csip); > +void bt_csip_unref(struct bt_csip *csip); > + > +void bt_csip_add_db(struct gatt_db *db); > + > +bool bt_csip_attach(struct bt_csip *csip, struct bt_gatt_client *client); > +void bt_csip_detach(struct bt_csip *csip); > + > +bool bt_csip_set_debug(struct bt_csip *csip, bt_csip_debug_func_t func, > + void *user_data, bt_csip_destroy_func_t destroy); > + > +struct bt_att *bt_csip_get_att(struct bt_csip *csip); > + > +bool bt_csip_set_user_data(struct bt_csip *csip, void *user_data); > + > +/* Session related function */ > +unsigned int bt_csip_register(bt_csip_func_t added, bt_csip_func_t removed, > + void *user_data); > +bool bt_csip_unregister(unsigned int id); > +struct bt_csip *bt_csip_new(struct gatt_db *ldb, struct gatt_db *rdb); > + > -- > 2.25.1 > -- Luiz Augusto von Dentz