Bluetooth: Audio: Rename CSIS to CSIP
Renamed the coordinated set implementation to use the profile (CSIP) name instead of the service (CSIS) name, as the former is more general. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
22002b8717
commit
93b3944a51
38 changed files with 1028 additions and 1006 deletions
|
@ -30,10 +30,10 @@ zephyr_library_sources_ifdef(CONFIG_BT_CCID ccid.c)
|
|||
|
||||
zephyr_library_link_libraries(subsys__bluetooth)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_CSIS csis.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_CSIS_CLIENT csis_client.c)
|
||||
if (CONFIG_BT_CSIS OR CONFIG_BT_CSIS_CLIENT)
|
||||
zephyr_library_sources(csis_crypto.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_CSIP csip.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_CSIP_SET_COORDINATOR csip_set_coordinator.c)
|
||||
if (CONFIG_BT_CSIP OR CONFIG_BT_CSIP_SET_COORDINATOR)
|
||||
zephyr_library_sources(csip_crypto.c)
|
||||
endif()
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_TBS tbs.c)
|
||||
|
|
|
@ -30,7 +30,7 @@ rsource "Kconfig.vocs"
|
|||
rsource "Kconfig.aics"
|
||||
rsource "Kconfig.vcs"
|
||||
rsource "Kconfig.micp"
|
||||
rsource "Kconfig.csis"
|
||||
rsource "Kconfig.csip"
|
||||
rsource "Kconfig.tbs"
|
||||
rsource "Kconfig.mcs"
|
||||
rsource "Kconfig.bass"
|
||||
|
|
|
@ -19,12 +19,12 @@ config BT_CAP_ACCEPTOR
|
|||
config BT_CAP_ACCEPTOR_SET_MEMBER
|
||||
bool "Common Audio Profile Acceptor Role Set Member support"
|
||||
depends on BT_CAP_ACCEPTOR
|
||||
depends on BT_CSIS
|
||||
depends on BT_CSIP
|
||||
help
|
||||
Enabling this will allow a CAP acceptor to be a set member.
|
||||
Enabling this will require a manual register of the CAS service.
|
||||
Enabling will take one of the allocated CSIS instances
|
||||
(BT_CSIS_MAX_INSTANCE_COUNT).
|
||||
(BT_CSIP_MAX_INSTANCE_COUNT).
|
||||
|
||||
config BT_DEBUG_CAP_ACCEPTOR
|
||||
bool "Common Audio Profile debug"
|
||||
|
@ -35,7 +35,7 @@ config BT_DEBUG_CAP_ACCEPTOR
|
|||
|
||||
config BT_CAP_INITIATOR
|
||||
bool "Common Audio Profile Initiator Role Support [EXPERIMENTAL]"
|
||||
depends on (BT_AUDIO_UNICAST_CLIENT && BT_CSIS_CLIENT) || BT_AUDIO_BROADCAST_SOURCE
|
||||
depends on (BT_AUDIO_UNICAST_CLIENT && BT_CSIP_SET_COORDINATOR) || BT_AUDIO_BROADCAST_SOURCE
|
||||
select EXPERIMENTAL
|
||||
help
|
||||
Enabling this will enable the CAP Initiator role.
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#################### Coordinated Set Identification Service ####################
|
||||
|
||||
config BT_CSIS
|
||||
config BT_CSIP
|
||||
bool "Coordinated Set Identification Service Support [EXPERIMENTAL]"
|
||||
imply BT_EXT_ADV if BT_PRIVACY
|
||||
select EXPERIMENTAL
|
||||
|
@ -16,9 +16,9 @@ config BT_CSIS
|
|||
This option enables support for Coordinated Set Identification
|
||||
Service.
|
||||
|
||||
if BT_CSIS
|
||||
if BT_CSIP
|
||||
|
||||
config BT_CSIS_TEST_SAMPLE_DATA
|
||||
config BT_CSIP_TEST_SAMPLE_DATA
|
||||
bool "Coordinated Set Identification Service Test Sample Data"
|
||||
help
|
||||
Enable the use of the sample data defined by the CSIS spec SIRK.
|
||||
|
@ -28,13 +28,13 @@ config BT_CSIS_TEST_SAMPLE_DATA
|
|||
(if encrypted) using public sample data.
|
||||
Should not be used for production builds.
|
||||
|
||||
config BT_CSIS_ENC_SIRK_SUPPORT
|
||||
config BT_CSIP_ENC_SIRK_SUPPORT
|
||||
bool "Support for encrypted SIRK"
|
||||
default y
|
||||
help
|
||||
Enables support encrypting the SIRK.
|
||||
|
||||
config BT_CSIS_MAX_INSTANCE_COUNT
|
||||
config BT_CSIP_MAX_INSTANCE_COUNT
|
||||
int "Coordinated Set Identification Service max instance count"
|
||||
default 1
|
||||
range 1 255
|
||||
|
@ -48,28 +48,28 @@ config BT_CSIS_MAX_INSTANCE_COUNT
|
|||
|
||||
############### DEBUG ###############
|
||||
|
||||
config BT_DEBUG_CSIS
|
||||
config BT_DEBUG_CSIP
|
||||
bool "Coordinated Set Identification Service debug"
|
||||
help
|
||||
Use this option to enable Coordinated Set Identification Service debug
|
||||
logs for the Bluetooth Audio functionality.
|
||||
|
||||
endif # BT_CSIS
|
||||
endif # BT_CSIP
|
||||
|
||||
#################### Coordinated Set Identification Client ####################
|
||||
|
||||
config BT_CSIS_CLIENT
|
||||
bool "Coordinated Set Identification Profile Support [EXPERIMENTAL]"
|
||||
config BT_CSIP_SET_COORDINATOR
|
||||
bool "Coordinated Set Identification Profile Set Coordinator Support [EXPERIMENTAL]"
|
||||
select BT_GATT_CLIENT
|
||||
select BT_GATT_AUTO_DISCOVER_CCC
|
||||
select EXPERIMENTAL
|
||||
help
|
||||
This option enables support for Coordinated Set Identification
|
||||
Profile.
|
||||
Profile Set Coordinator.
|
||||
|
||||
if BT_CSIS_CLIENT
|
||||
if BT_CSIP_SET_COORDINATOR
|
||||
|
||||
config BT_CSIS_CLIENT_TEST_SAMPLE_DATA
|
||||
config BT_CSIP_SET_COORDINATOR_TEST_SAMPLE_DATA
|
||||
bool "Coordinated Set Identification Service Test Sample Data"
|
||||
help
|
||||
Enable the use of the sample data defined by the CSIS spec.
|
||||
|
@ -80,7 +80,7 @@ config BT_CSIS_CLIENT_TEST_SAMPLE_DATA
|
|||
with set members that are not using the sample data.
|
||||
Should not be used for production builds.
|
||||
|
||||
config BT_CSIS_CLIENT_MAX_CSIS_INSTANCES
|
||||
config BT_CSIP_SET_COORDINATOR_MAX_CSIS_INSTANCES
|
||||
int "Coordinated Set Identification Service Count"
|
||||
default 1
|
||||
range 1 3
|
||||
|
@ -88,7 +88,7 @@ config BT_CSIS_CLIENT_MAX_CSIS_INSTANCES
|
|||
Sets the number of service instances, which corresponds to the number
|
||||
of different sets the peer device may be in.
|
||||
|
||||
config BT_CSIS_CLIENT_ENC_SIRK_SUPPORT
|
||||
config BT_CSIP_SET_COORDINATOR_ENC_SIRK_SUPPORT
|
||||
bool "Support for encrypted SIRK"
|
||||
default y
|
||||
help
|
||||
|
@ -96,17 +96,17 @@ config BT_CSIS_CLIENT_ENC_SIRK_SUPPORT
|
|||
|
||||
############### DEBUG ###############
|
||||
|
||||
config BT_DEBUG_CSIS_CLIENT
|
||||
config BT_DEBUG_CSIP_SET_COORDINATOR
|
||||
bool "Coordinated Set Identification Profile debug"
|
||||
help
|
||||
Use this option to enable Coordinated Set Identification Profile debug
|
||||
logs for the Bluetooth Audio functionality.
|
||||
|
||||
endif # BT_CSIS_CLIENT
|
||||
endif # BT_CSIP_SET_COORDINATOR
|
||||
|
||||
config BT_DEBUG_CSIS_CRYPTO
|
||||
bool "Coordinated Set Identification Service crypto functions debug"
|
||||
depends on BT_CSIS_CLIENT || BT_CSIS
|
||||
config BT_DEBUG_CSIP_CRYPTO
|
||||
bool "Coordinated Set Identification Profile crypto functions debug"
|
||||
depends on BT_CSIP_SET_COORDINATOR || BT_CSIP
|
||||
help
|
||||
Use this option to enable Coordinated Set Identification Service
|
||||
Use this option to enable Coordinated Set Identification Profile
|
||||
crypto functions debug logs for the Bluetooth Audio functionality.
|
|
@ -23,7 +23,7 @@ config BT_HAS_HEARING_AID_MONAURAL
|
|||
bool "Monaural Hearing Aid"
|
||||
|
||||
config BT_HAS_HEARING_AID_BINAURAL
|
||||
depends on BT_CSIS
|
||||
depends on BT_CSIP
|
||||
bool "Binaural Hearing Aid"
|
||||
|
||||
config BT_HAS_HEARING_AID_BANDED
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <zephyr/sys/check.h>
|
||||
#include <zephyr/bluetooth/gatt.h>
|
||||
#include <zephyr/bluetooth/audio/tbs.h>
|
||||
#include <zephyr/bluetooth/audio/csis.h>
|
||||
#include <zephyr/bluetooth/audio/csip.h>
|
||||
#include "cap_internal.h"
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CAP_ACCEPTOR)
|
||||
|
@ -21,22 +21,22 @@ static struct bt_gatt_attr svc_attrs[] = {
|
|||
BT_GATT_INCLUDE_SERVICE(NULL) /* To be overwritten */
|
||||
};
|
||||
|
||||
int bt_cap_acceptor_register(const struct bt_csis_register_param *param,
|
||||
struct bt_csis **csis)
|
||||
int bt_cap_acceptor_register(const struct bt_csip_register_param *param,
|
||||
struct bt_csip **csip)
|
||||
{
|
||||
static struct bt_gatt_service cas;
|
||||
int err;
|
||||
|
||||
err = bt_csis_register(param, csis);
|
||||
err = bt_csip_register(param, csip);
|
||||
if (err != 0) {
|
||||
BT_DBG("Failed to register CSIS");
|
||||
BT_DBG("Failed to register CSIP");
|
||||
return err;
|
||||
}
|
||||
|
||||
cas = (struct bt_gatt_service)BT_GATT_SERVICE(svc_attrs);
|
||||
|
||||
/* Overwrite the include definition with the CSIS */
|
||||
cas.attrs[1].user_data = bt_csis_svc_decl_get(*csis);
|
||||
/* Overwrite the include definition with the CSIP */
|
||||
cas.attrs[1].user_data = bt_csip_svc_decl_get(*csip);
|
||||
|
||||
err = bt_gatt_service_register(&cas);
|
||||
if (err) {
|
||||
|
@ -51,7 +51,7 @@ int bt_cap_acceptor_register(const struct bt_csis_register_param *param,
|
|||
|
||||
BT_GATT_SERVICE_DEFINE(cas_svc,
|
||||
BT_GATT_PRIMARY_SERVICE(BT_UUID_CAS)
|
||||
/* TODO: Add support for included CSIS */
|
||||
/* TODO: Add support for included CSIP */
|
||||
);
|
||||
|
||||
#endif /* CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER */
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <zephyr/bluetooth/audio/tbs.h>
|
||||
#include <zephyr/bluetooth/audio/cap.h>
|
||||
#include "cap_internal.h"
|
||||
#include "csis_internal.h"
|
||||
#include "csip_internal.h"
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_CAP_INITIATOR)
|
||||
#define LOG_MODULE_NAME bt_cap_initiator
|
||||
|
@ -62,13 +62,13 @@ static const struct bt_uuid *cas_uuid = BT_UUID_CAS;
|
|||
struct cap_unicast_client {
|
||||
struct bt_gatt_discover_params param;
|
||||
uint16_t csis_start_handle;
|
||||
const struct bt_csis_client_csis_inst *csis_inst;
|
||||
const struct bt_csip_set_coordinator_csis_inst *csis_inst;
|
||||
};
|
||||
|
||||
static struct cap_unicast_client bt_cap_unicast_clients[CONFIG_BT_MAX_CONN];
|
||||
|
||||
static void csis_client_discover_cb(struct bt_conn *conn,
|
||||
const struct bt_csis_client_set_member *member,
|
||||
const struct bt_csip_set_coordinator_set_member *member,
|
||||
int err, size_t set_count)
|
||||
{
|
||||
struct cap_unicast_client *client;
|
||||
|
@ -84,7 +84,7 @@ static void csis_client_discover_cb(struct bt_conn *conn,
|
|||
}
|
||||
|
||||
client = &bt_cap_unicast_clients[bt_conn_index(conn)];
|
||||
client->csis_inst = bt_csis_client_csis_inst_by_handle(
|
||||
client->csis_inst = bt_csip_set_coordinator_csis_inst_by_handle(
|
||||
conn, client->csis_start_handle);
|
||||
|
||||
if (member == NULL || set_count == 0 || client->csis_inst == NULL) {
|
||||
|
@ -127,11 +127,11 @@ static uint8_t cap_unicast_discover_included_cb(struct bt_conn *conn,
|
|||
* CSIS discovery
|
||||
*/
|
||||
client->csis_start_handle = included_service->start_handle;
|
||||
client->csis_inst = bt_csis_client_csis_inst_by_handle(
|
||||
client->csis_inst = bt_csip_set_coordinator_csis_inst_by_handle(
|
||||
conn, client->csis_start_handle);
|
||||
|
||||
if (client->csis_inst == NULL) {
|
||||
static struct bt_csis_client_cb csis_client_cb = {
|
||||
static struct bt_csip_set_coordinator_cb csis_client_cb = {
|
||||
.discover = csis_client_discover_cb
|
||||
};
|
||||
static bool csis_cbs_registered;
|
||||
|
@ -140,11 +140,11 @@ static uint8_t cap_unicast_discover_included_cb(struct bt_conn *conn,
|
|||
BT_DBG("CAS CSIS not known, discovering");
|
||||
|
||||
if (!csis_cbs_registered) {
|
||||
bt_csis_client_register_cb(&csis_client_cb);
|
||||
bt_csip_set_coordinator_register_cb(&csis_client_cb);
|
||||
csis_cbs_registered = true;
|
||||
}
|
||||
|
||||
err = bt_csis_client_discover(conn);
|
||||
err = bt_csip_set_coordinator_discover(conn);
|
||||
if (err != 0) {
|
||||
BT_DBG("Discover failed (err %d)", err);
|
||||
if (cap_cb && cap_cb->unicast_discovery_complete) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Bluetooth CSIS - Coordinated Set Identification Service */
|
||||
/* Bluetooth CSIP - Coordinated Set Identification Profile */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019 Bose Corporation
|
||||
* Copyright (c) 2020-2021 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2020-2022 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -22,65 +22,65 @@
|
|||
#include <zephyr/sys/check.h>
|
||||
|
||||
#include "audio_internal.h"
|
||||
#include "csis_internal.h"
|
||||
#include "csis_crypto.h"
|
||||
#include "csip_internal.h"
|
||||
#include "csip_crypto.h"
|
||||
#include "../host/conn_internal.h"
|
||||
#include "../host/hci_core.h"
|
||||
#include "../host/keys.h"
|
||||
|
||||
#define BT_CSIS_SIH_PRAND_SIZE 3
|
||||
#define BT_CSIS_SIH_HASH_SIZE 3
|
||||
#define CSIS_SET_LOCK_TIMER_VALUE K_SECONDS(60)
|
||||
#define BT_CSIP_SIH_PRAND_SIZE 3
|
||||
#define BT_CSIP_SIH_HASH_SIZE 3
|
||||
#define CSIP_SET_LOCK_TIMER_VALUE K_SECONDS(60)
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIS)
|
||||
#define LOG_MODULE_NAME bt_csis
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIP)
|
||||
#define LOG_MODULE_NAME bt_csip
|
||||
#include "common/log.h"
|
||||
#include "common/bt_str.h"
|
||||
|
||||
static struct bt_csis csis_insts[CONFIG_BT_CSIS_MAX_INSTANCE_COUNT];
|
||||
static struct bt_csip csip_insts[CONFIG_BT_CSIP_MAX_INSTANCE_COUNT];
|
||||
static bt_addr_le_t server_dummy_addr; /* 0'ed address */
|
||||
|
||||
struct csis_notify_foreach {
|
||||
struct csip_notify_foreach {
|
||||
struct bt_conn *excluded_client;
|
||||
struct bt_csis *csis;
|
||||
struct bt_csip *csip;
|
||||
};
|
||||
|
||||
static bool is_last_client_to_write(const struct bt_csis *csis,
|
||||
static bool is_last_client_to_write(const struct bt_csip *csip,
|
||||
const struct bt_conn *conn)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
return bt_addr_le_eq(bt_conn_get_dst(conn),
|
||||
&csis->srv.lock_client_addr);
|
||||
&csip->srv.lock_client_addr);
|
||||
} else {
|
||||
return bt_addr_le_eq(&server_dummy_addr,
|
||||
&csis->srv.lock_client_addr);
|
||||
&csip->srv.lock_client_addr);
|
||||
}
|
||||
}
|
||||
|
||||
static void notify_lock_value(const struct bt_csis *csis, struct bt_conn *conn)
|
||||
static void notify_lock_value(const struct bt_csip *csip, struct bt_conn *conn)
|
||||
{
|
||||
bt_gatt_notify_uuid(conn, BT_UUID_CSIS_SET_LOCK,
|
||||
csis->srv.service_p->attrs,
|
||||
&csis->srv.set_lock,
|
||||
sizeof(csis->srv.set_lock));
|
||||
csip->srv.service_p->attrs,
|
||||
&csip->srv.set_lock,
|
||||
sizeof(csip->srv.set_lock));
|
||||
}
|
||||
|
||||
static void notify_client(struct bt_conn *conn, void *data)
|
||||
{
|
||||
struct csis_notify_foreach *csis_data = (struct csis_notify_foreach *)data;
|
||||
struct bt_csis *csis = csis_data->csis;
|
||||
struct bt_conn *excluded_conn = csis_data->excluded_client;
|
||||
struct csip_notify_foreach *csip_data = (struct csip_notify_foreach *)data;
|
||||
struct bt_csip *csip = csip_data->csip;
|
||||
struct bt_conn *excluded_conn = csip_data->excluded_client;
|
||||
|
||||
if (excluded_conn != NULL && conn == excluded_conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
notify_lock_value(csis, conn);
|
||||
notify_lock_value(csip, conn);
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(csis->srv.pend_notify); i++) {
|
||||
struct csis_pending_notifications *pend_notify;
|
||||
for (int i = 0; i < ARRAY_SIZE(csip->srv.pend_notify); i++) {
|
||||
struct csip_pending_notifications *pend_notify;
|
||||
|
||||
pend_notify = &csis->srv.pend_notify[i];
|
||||
pend_notify = &csip->srv.pend_notify[i];
|
||||
|
||||
if (pend_notify->pending &&
|
||||
bt_addr_le_eq(bt_conn_get_dst(conn), &pend_notify->addr)) {
|
||||
|
@ -90,21 +90,21 @@ static void notify_client(struct bt_conn *conn, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void notify_clients(struct bt_csis *csis,
|
||||
static void notify_clients(struct bt_csip *csip,
|
||||
struct bt_conn *excluded_client)
|
||||
{
|
||||
struct csis_notify_foreach data = {
|
||||
struct csip_notify_foreach data = {
|
||||
.excluded_client = excluded_client,
|
||||
.csis = csis,
|
||||
.csip = csip,
|
||||
};
|
||||
|
||||
/* Mark all bonded devices as pending notifications, and clear those
|
||||
* that are notified in `notify_client`
|
||||
*/
|
||||
for (int i = 0; i < ARRAY_SIZE(csis->srv.pend_notify); i++) {
|
||||
struct csis_pending_notifications *pend_notify;
|
||||
for (int i = 0; i < ARRAY_SIZE(csip->srv.pend_notify); i++) {
|
||||
struct csip_pending_notifications *pend_notify;
|
||||
|
||||
pend_notify = &csis->srv.pend_notify[i];
|
||||
pend_notify = &csip->srv.pend_notify[i];
|
||||
|
||||
if (pend_notify->active) {
|
||||
if (excluded_client != NULL &&
|
||||
|
@ -120,13 +120,13 @@ static void notify_clients(struct bt_csis *csis,
|
|||
}
|
||||
|
||||
static int sirk_encrypt(struct bt_conn *conn,
|
||||
const struct bt_csis_set_sirk *sirk,
|
||||
struct bt_csis_set_sirk *enc_sirk)
|
||||
const struct bt_csip_set_sirk *sirk,
|
||||
struct bt_csip_set_sirk *enc_sirk)
|
||||
{
|
||||
int err;
|
||||
uint8_t *k;
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_CSIS_TEST_SAMPLE_DATA)) {
|
||||
if (IS_ENABLED(CONFIG_BT_CSIP_TEST_SAMPLE_DATA)) {
|
||||
/* test_k is from the sample data from A.2 in the CSIS spec */
|
||||
static uint8_t test_k[] = {0x67, 0x6e, 0x1b, 0x9b,
|
||||
0xd4, 0x48, 0x69, 0x6f,
|
||||
|
@ -145,13 +145,13 @@ static int sirk_encrypt(struct bt_conn *conn,
|
|||
k = conn->le.keys->ltk.val;
|
||||
}
|
||||
|
||||
err = bt_csis_sef(k, sirk->value, enc_sirk->value);
|
||||
err = bt_csip_sef(k, sirk->value, enc_sirk->value);
|
||||
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
enc_sirk->type = BT_CSIS_SIRK_TYPE_ENCRYPTED;
|
||||
enc_sirk->type = BT_CSIP_SIRK_TYPE_ENCRYPTED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ static int generate_prand(uint32_t *dest)
|
|||
int res;
|
||||
|
||||
*dest = 0;
|
||||
res = bt_rand(dest, BT_CSIS_SIH_PRAND_SIZE);
|
||||
res = bt_rand(dest, BT_CSIP_SIH_PRAND_SIZE);
|
||||
if (res != 0) {
|
||||
return res;
|
||||
}
|
||||
|
@ -181,13 +181,13 @@ static int generate_prand(uint32_t *dest)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int bt_csis_generate_rsi(const struct bt_csis *csis, uint8_t rsi[BT_CSIS_RSI_SIZE])
|
||||
int bt_csip_generate_rsi(const struct bt_csip *csip, uint8_t rsi[BT_CSIP_RSI_SIZE])
|
||||
{
|
||||
int res = 0;
|
||||
uint32_t prand;
|
||||
uint32_t hash;
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_CSIS_TEST_SAMPLE_DATA)) {
|
||||
if (IS_ENABLED(CONFIG_BT_CSIP_TEST_SAMPLE_DATA)) {
|
||||
/* prand is from the sample data from A.2 in the CSIS spec */
|
||||
prand = 0x69f563;
|
||||
} else {
|
||||
|
@ -199,14 +199,14 @@ int bt_csis_generate_rsi(const struct bt_csis *csis, uint8_t rsi[BT_CSIS_RSI_SIZ
|
|||
}
|
||||
}
|
||||
|
||||
res = bt_csis_sih(csis->srv.set_sirk.value, prand, &hash);
|
||||
res = bt_csip_sih(csip->srv.set_sirk.value, prand, &hash);
|
||||
if (res != 0) {
|
||||
BT_WARN("Could not generate new RSI");
|
||||
return res;
|
||||
}
|
||||
|
||||
(void)memcpy(rsi, &hash, BT_CSIS_SIH_HASH_SIZE);
|
||||
(void)memcpy(rsi + BT_CSIS_SIH_HASH_SIZE, &prand, BT_CSIS_SIH_PRAND_SIZE);
|
||||
(void)memcpy(rsi, &hash, BT_CSIP_SIH_HASH_SIZE);
|
||||
(void)memcpy(rsi + BT_CSIP_SIH_HASH_SIZE, &prand, BT_CSIP_SIH_PRAND_SIZE);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -215,23 +215,23 @@ static ssize_t read_set_sirk(struct bt_conn *conn,
|
|||
const struct bt_gatt_attr *attr,
|
||||
void *buf, uint16_t len, uint16_t offset)
|
||||
{
|
||||
struct bt_csis_set_sirk enc_sirk;
|
||||
struct bt_csis_set_sirk *sirk;
|
||||
struct bt_csis *csis = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
struct bt_csip_set_sirk enc_sirk;
|
||||
struct bt_csip_set_sirk *sirk;
|
||||
struct bt_csip *csip = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
|
||||
if (csis->srv.cb != NULL && csis->srv.cb->sirk_read_req != NULL) {
|
||||
if (csip->srv.cb != NULL && csip->srv.cb->sirk_read_req != NULL) {
|
||||
uint8_t cb_rsp;
|
||||
|
||||
/* Ask higher layer for what SIRK to return, if any */
|
||||
cb_rsp = csis->srv.cb->sirk_read_req(conn, &csis_insts[0]);
|
||||
cb_rsp = csip->srv.cb->sirk_read_req(conn, &csip_insts[0]);
|
||||
|
||||
if (cb_rsp == BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT) {
|
||||
sirk = &csis->srv.set_sirk;
|
||||
} else if (IS_ENABLED(CONFIG_BT_CSIS_ENC_SIRK_SUPPORT) &&
|
||||
cb_rsp == BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT_ENC) {
|
||||
if (cb_rsp == BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT) {
|
||||
sirk = &csip->srv.set_sirk;
|
||||
} else if (IS_ENABLED(CONFIG_BT_CSIP_ENC_SIRK_SUPPORT) &&
|
||||
cb_rsp == BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT_ENC) {
|
||||
int err;
|
||||
|
||||
err = sirk_encrypt(conn, &csis->srv.set_sirk,
|
||||
err = sirk_encrypt(conn, &csip->srv.set_sirk,
|
||||
&enc_sirk);
|
||||
if (err != 0) {
|
||||
BT_ERR("Could not encrypt SIRK: %d",
|
||||
|
@ -242,22 +242,23 @@ static ssize_t read_set_sirk(struct bt_conn *conn,
|
|||
sirk = &enc_sirk;
|
||||
LOG_HEXDUMP_DBG(enc_sirk.value, sizeof(enc_sirk.value),
|
||||
"Encrypted Set SIRK");
|
||||
} else if (cb_rsp == BT_CSIS_READ_SIRK_REQ_RSP_REJECT) {
|
||||
} else if (cb_rsp == BT_CSIP_READ_SIRK_REQ_RSP_REJECT) {
|
||||
return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION);
|
||||
} else if (cb_rsp == BT_CSIS_READ_SIRK_REQ_RSP_OOB_ONLY) {
|
||||
return BT_GATT_ERR(BT_CSIS_ERROR_SIRK_OOB_ONLY);
|
||||
} else if (cb_rsp == BT_CSIP_READ_SIRK_REQ_RSP_OOB_ONLY) {
|
||||
return BT_GATT_ERR(BT_CSIP_ERROR_SIRK_OOB_ONLY);
|
||||
} else {
|
||||
BT_ERR("Invalid callback response: %u", cb_rsp);
|
||||
return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
|
||||
}
|
||||
} else {
|
||||
sirk = &csis->srv.set_sirk;
|
||||
sirk = &csip->srv.set_sirk;
|
||||
}
|
||||
|
||||
|
||||
BT_DBG("Set sirk %sencrypted",
|
||||
sirk->type == BT_CSIS_SIRK_TYPE_PLAIN ? "not " : "");
|
||||
LOG_HEXDUMP_DBG(csis->srv.set_sirk.value, sizeof(csis->srv.set_sirk.value), "Set SIRK");
|
||||
sirk->type == BT_CSIP_SIRK_TYPE_PLAIN ? "not " : "");
|
||||
LOG_HEXDUMP_DBG(csip->srv.set_sirk.value,
|
||||
sizeof(csip->srv.set_sirk.value), "Set SIRK");
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset,
|
||||
sirk, sizeof(*sirk));
|
||||
}
|
||||
|
@ -272,13 +273,13 @@ static ssize_t read_set_size(struct bt_conn *conn,
|
|||
const struct bt_gatt_attr *attr,
|
||||
void *buf, uint16_t len, uint16_t offset)
|
||||
{
|
||||
struct bt_csis *csis = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
struct bt_csip *csip = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
|
||||
BT_DBG("%u", csis->srv.set_size);
|
||||
BT_DBG("%u", csip->srv.set_size);
|
||||
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset,
|
||||
&csis->srv.set_size,
|
||||
sizeof(csis->srv.set_size));
|
||||
&csip->srv.set_size,
|
||||
sizeof(csip->srv.set_size));
|
||||
}
|
||||
|
||||
static void set_size_cfg_changed(const struct bt_gatt_attr *attr,
|
||||
|
@ -291,62 +292,62 @@ static ssize_t read_set_lock(struct bt_conn *conn,
|
|||
const struct bt_gatt_attr *attr,
|
||||
void *buf, uint16_t len, uint16_t offset)
|
||||
{
|
||||
struct bt_csis *csis = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
struct bt_csip *csip = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
|
||||
BT_DBG("%u", csis->srv.set_lock);
|
||||
BT_DBG("%u", csip->srv.set_lock);
|
||||
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset,
|
||||
&csis->srv.set_lock,
|
||||
sizeof(csis->srv.set_lock));
|
||||
&csip->srv.set_lock,
|
||||
sizeof(csip->srv.set_lock));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the lock value of a CSIS instance.
|
||||
* @brief Set the lock value of a CSIP instance.
|
||||
*
|
||||
* @param conn The connection locking the instance.
|
||||
* Will be NULL if the server locally sets the lock.
|
||||
* @param csis The CSIS instance to change the lock value of
|
||||
* @param val The lock value (BT_CSIS_LOCK_VALUE or BT_CSIS_RELEASE_VALUE)
|
||||
* @param csip The CSIP instance to change the lock value of
|
||||
* @param val The lock value (BT_CSIP_LOCK_VALUE or BT_CSIP_RELEASE_VALUE)
|
||||
*
|
||||
* @return BT_CSIS_ERROR_* on failure or 0 if success
|
||||
* @return BT_CSIP_ERROR_* on failure or 0 if success
|
||||
*/
|
||||
static uint8_t set_lock(struct bt_conn *conn, struct bt_csis *csis, uint8_t val)
|
||||
static uint8_t set_lock(struct bt_conn *conn, struct bt_csip *csip, uint8_t val)
|
||||
{
|
||||
bool notify;
|
||||
|
||||
if (val != BT_CSIS_RELEASE_VALUE && val != BT_CSIS_LOCK_VALUE) {
|
||||
return BT_CSIS_ERROR_LOCK_INVAL_VALUE;
|
||||
if (val != BT_CSIP_RELEASE_VALUE && val != BT_CSIP_LOCK_VALUE) {
|
||||
return BT_CSIP_ERROR_LOCK_INVAL_VALUE;
|
||||
}
|
||||
|
||||
if (csis->srv.set_lock == BT_CSIS_LOCK_VALUE) {
|
||||
if (val == BT_CSIS_LOCK_VALUE) {
|
||||
if (is_last_client_to_write(csis, conn)) {
|
||||
return BT_CSIS_ERROR_LOCK_ALREADY_GRANTED;
|
||||
if (csip->srv.set_lock == BT_CSIP_LOCK_VALUE) {
|
||||
if (val == BT_CSIP_LOCK_VALUE) {
|
||||
if (is_last_client_to_write(csip, conn)) {
|
||||
return BT_CSIP_ERROR_LOCK_ALREADY_GRANTED;
|
||||
} else {
|
||||
return BT_CSIS_ERROR_LOCK_DENIED;
|
||||
return BT_CSIP_ERROR_LOCK_DENIED;
|
||||
}
|
||||
} else if (!is_last_client_to_write(csis, conn)) {
|
||||
return BT_CSIS_ERROR_LOCK_RELEASE_DENIED;
|
||||
} else if (!is_last_client_to_write(csip, conn)) {
|
||||
return BT_CSIP_ERROR_LOCK_RELEASE_DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
notify = csis->srv.set_lock != val;
|
||||
notify = csip->srv.set_lock != val;
|
||||
|
||||
csis->srv.set_lock = val;
|
||||
if (csis->srv.set_lock == BT_CSIS_LOCK_VALUE) {
|
||||
csip->srv.set_lock = val;
|
||||
if (csip->srv.set_lock == BT_CSIP_LOCK_VALUE) {
|
||||
if (conn != NULL) {
|
||||
bt_addr_le_copy(&csis->srv.lock_client_addr,
|
||||
bt_addr_le_copy(&csip->srv.lock_client_addr,
|
||||
bt_conn_get_dst(conn));
|
||||
}
|
||||
(void)k_work_reschedule(&csis->srv.set_lock_timer,
|
||||
CSIS_SET_LOCK_TIMER_VALUE);
|
||||
(void)k_work_reschedule(&csip->srv.set_lock_timer,
|
||||
CSIP_SET_LOCK_TIMER_VALUE);
|
||||
} else {
|
||||
(void)memset(&csis->srv.lock_client_addr, 0,
|
||||
sizeof(csis->srv.lock_client_addr));
|
||||
(void)k_work_cancel_delayable(&csis->srv.set_lock_timer);
|
||||
(void)memset(&csip->srv.lock_client_addr, 0,
|
||||
sizeof(csip->srv.lock_client_addr));
|
||||
(void)k_work_cancel_delayable(&csip->srv.set_lock_timer);
|
||||
}
|
||||
|
||||
BT_DBG("%u", csis->srv.set_lock);
|
||||
BT_DBG("%u", csip->srv.set_lock);
|
||||
|
||||
if (notify) {
|
||||
/*
|
||||
|
@ -354,12 +355,12 @@ static uint8_t set_lock(struct bt_conn *conn, struct bt_csis *csis, uint8_t val)
|
|||
* client writing the value, shall be notified
|
||||
* (if subscribed)
|
||||
*/
|
||||
notify_clients(csis, conn);
|
||||
notify_clients(csip, conn);
|
||||
|
||||
if (csis->srv.cb != NULL && csis->srv.cb->lock_changed != NULL) {
|
||||
bool locked = csis->srv.set_lock == BT_CSIS_LOCK_VALUE;
|
||||
if (csip->srv.cb != NULL && csip->srv.cb->lock_changed != NULL) {
|
||||
bool locked = csip->srv.set_lock == BT_CSIP_LOCK_VALUE;
|
||||
|
||||
csis->srv.cb->lock_changed(conn, csis, locked);
|
||||
csip->srv.cb->lock_changed(conn, csip, locked);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,7 +374,7 @@ static ssize_t write_set_lock(struct bt_conn *conn,
|
|||
{
|
||||
ssize_t res;
|
||||
uint8_t val;
|
||||
struct bt_csis *csis = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
struct bt_csip *csip = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
|
||||
if (offset != 0) {
|
||||
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
|
||||
|
@ -383,7 +384,7 @@ static ssize_t write_set_lock(struct bt_conn *conn,
|
|||
|
||||
(void)memcpy(&val, buf, len);
|
||||
|
||||
res = set_lock(conn, csis, val);
|
||||
res = set_lock(conn, csip, val);
|
||||
if (res != BT_ATT_ERR_SUCCESS) {
|
||||
return BT_GATT_ERR(res);
|
||||
}
|
||||
|
@ -400,38 +401,38 @@ static void set_lock_cfg_changed(const struct bt_gatt_attr *attr,
|
|||
static ssize_t read_rank(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||
void *buf, uint16_t len, uint16_t offset)
|
||||
{
|
||||
struct bt_csis *csis = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
struct bt_csip *csip = BT_AUDIO_CHRC_USER_DATA(attr);
|
||||
|
||||
BT_DBG("%u", csis->srv.rank);
|
||||
BT_DBG("%u", csip->srv.rank);
|
||||
|
||||
return bt_gatt_attr_read(conn, attr, buf, len, offset,
|
||||
&csis->srv.rank,
|
||||
sizeof(csis->srv.rank));
|
||||
&csip->srv.rank,
|
||||
sizeof(csip->srv.rank));
|
||||
|
||||
}
|
||||
|
||||
static void set_lock_timer_handler(struct k_work *work)
|
||||
{
|
||||
struct k_work_delayable *delayable;
|
||||
struct bt_csis_server *server;
|
||||
struct bt_csis *csis;
|
||||
struct bt_csip_server *server;
|
||||
struct bt_csip *csip;
|
||||
|
||||
delayable = CONTAINER_OF(work, struct k_work_delayable, work);
|
||||
server = CONTAINER_OF(delayable, struct bt_csis_server, set_lock_timer);
|
||||
csis = CONTAINER_OF(server, struct bt_csis, srv);
|
||||
server = CONTAINER_OF(delayable, struct bt_csip_server, set_lock_timer);
|
||||
csip = CONTAINER_OF(server, struct bt_csip, srv);
|
||||
|
||||
BT_DBG("Lock timeout, releasing");
|
||||
csis->srv.set_lock = BT_CSIS_RELEASE_VALUE;
|
||||
notify_clients(csis, NULL);
|
||||
csip->srv.set_lock = BT_CSIP_RELEASE_VALUE;
|
||||
notify_clients(csip, NULL);
|
||||
|
||||
if (csis->srv.cb != NULL && csis->srv.cb->lock_changed != NULL) {
|
||||
bool locked = csis->srv.set_lock == BT_CSIS_LOCK_VALUE;
|
||||
if (csip->srv.cb != NULL && csip->srv.cb->lock_changed != NULL) {
|
||||
bool locked = csip->srv.set_lock == BT_CSIP_LOCK_VALUE;
|
||||
|
||||
csis->srv.cb->lock_changed(NULL, csis, locked);
|
||||
csip->srv.cb->lock_changed(NULL, csip, locked);
|
||||
}
|
||||
}
|
||||
|
||||
static void csis_security_changed(struct bt_conn *conn, bt_security_t level,
|
||||
static void csip_security_changed(struct bt_conn *conn, bt_security_t level,
|
||||
enum bt_security_err err)
|
||||
{
|
||||
if (err != 0 || conn->encrypt == 0) {
|
||||
|
@ -442,17 +443,17 @@ static void csis_security_changed(struct bt_conn *conn, bt_security_t level,
|
|||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(csis_insts); i++) {
|
||||
struct bt_csis *csis = &csis_insts[i];
|
||||
for (int i = 0; i < ARRAY_SIZE(csip_insts); i++) {
|
||||
struct bt_csip *csip = &csip_insts[i];
|
||||
|
||||
for (int j = 0; j < ARRAY_SIZE(csis->srv.pend_notify); j++) {
|
||||
struct csis_pending_notifications *pend_notify;
|
||||
for (int j = 0; j < ARRAY_SIZE(csip->srv.pend_notify); j++) {
|
||||
struct csip_pending_notifications *pend_notify;
|
||||
|
||||
pend_notify = &csis->srv.pend_notify[j];
|
||||
pend_notify = &csip->srv.pend_notify[j];
|
||||
|
||||
if (pend_notify->pending &&
|
||||
bt_addr_le_eq(bt_conn_get_dst(conn), &pend_notify->addr)) {
|
||||
notify_lock_value(csis, conn);
|
||||
notify_lock_value(csip, conn);
|
||||
pend_notify->pending = false;
|
||||
break;
|
||||
}
|
||||
|
@ -460,29 +461,29 @@ static void csis_security_changed(struct bt_conn *conn, bt_security_t level,
|
|||
}
|
||||
}
|
||||
|
||||
static void handle_csis_disconnect(struct bt_csis *csis, struct bt_conn *conn)
|
||||
static void handle_csip_disconnect(struct bt_csip *csip, struct bt_conn *conn)
|
||||
{
|
||||
BT_DBG("Non-bonded device");
|
||||
if (is_last_client_to_write(csis, conn)) {
|
||||
(void)memset(&csis->srv.lock_client_addr, 0,
|
||||
sizeof(csis->srv.lock_client_addr));
|
||||
csis->srv.set_lock = BT_CSIS_RELEASE_VALUE;
|
||||
notify_clients(csis, NULL);
|
||||
if (is_last_client_to_write(csip, conn)) {
|
||||
(void)memset(&csip->srv.lock_client_addr, 0,
|
||||
sizeof(csip->srv.lock_client_addr));
|
||||
csip->srv.set_lock = BT_CSIP_RELEASE_VALUE;
|
||||
notify_clients(csip, NULL);
|
||||
|
||||
if (csis->srv.cb != NULL && csis->srv.cb->lock_changed != NULL) {
|
||||
bool locked = csis->srv.set_lock == BT_CSIS_LOCK_VALUE;
|
||||
if (csip->srv.cb != NULL && csip->srv.cb->lock_changed != NULL) {
|
||||
bool locked = csip->srv.set_lock == BT_CSIP_LOCK_VALUE;
|
||||
|
||||
csis->srv.cb->lock_changed(conn, csis, locked);
|
||||
csip->srv.cb->lock_changed(conn, csip, locked);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the disconnected device once was bonded and stored
|
||||
* here as a bonded device
|
||||
*/
|
||||
for (int i = 0; i < ARRAY_SIZE(csis->srv.pend_notify); i++) {
|
||||
struct csis_pending_notifications *pend_notify;
|
||||
for (int i = 0; i < ARRAY_SIZE(csip->srv.pend_notify); i++) {
|
||||
struct csip_pending_notifications *pend_notify;
|
||||
|
||||
pend_notify = &csis->srv.pend_notify[i];
|
||||
pend_notify = &csip->srv.pend_notify[i];
|
||||
|
||||
if (bt_addr_le_eq(bt_conn_get_dst(conn), &pend_notify->addr)) {
|
||||
(void)memset(pend_notify, 0, sizeof(*pend_notify));
|
||||
|
@ -491,60 +492,60 @@ static void handle_csis_disconnect(struct bt_csis *csis, struct bt_conn *conn)
|
|||
}
|
||||
}
|
||||
|
||||
static void csis_disconnected(struct bt_conn *conn, uint8_t reason)
|
||||
static void csip_disconnected(struct bt_conn *conn, uint8_t reason)
|
||||
{
|
||||
BT_DBG("Disconnected: %s (reason %u)",
|
||||
bt_addr_le_str(bt_conn_get_dst(conn)), reason);
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(csis_insts); i++) {
|
||||
handle_csis_disconnect(&csis_insts[i], conn);
|
||||
for (int i = 0; i < ARRAY_SIZE(csip_insts); i++) {
|
||||
handle_csip_disconnect(&csip_insts[i], conn);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_csis_auth_complete(struct bt_csis *csis,
|
||||
static void handle_csip_auth_complete(struct bt_csip *csip,
|
||||
struct bt_conn *conn)
|
||||
{
|
||||
/* Check if already in list, and do nothing if it is */
|
||||
for (int i = 0; i < ARRAY_SIZE(csis->srv.pend_notify); i++) {
|
||||
struct csis_pending_notifications *pend_notify;
|
||||
for (int i = 0; i < ARRAY_SIZE(csip->srv.pend_notify); i++) {
|
||||
struct csip_pending_notifications *pend_notify;
|
||||
|
||||
pend_notify = &csis->srv.pend_notify[i];
|
||||
pend_notify = &csip->srv.pend_notify[i];
|
||||
|
||||
if (pend_notify->active &&
|
||||
bt_addr_le_eq(bt_conn_get_dst(conn), &pend_notify->addr)) {
|
||||
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
|
||||
pend_notify->age = csis->srv.age_counter++;
|
||||
pend_notify->age = csip->srv.age_counter++;
|
||||
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy addr to list over devices to save notifications for */
|
||||
for (int i = 0; i < ARRAY_SIZE(csis->srv.pend_notify); i++) {
|
||||
struct csis_pending_notifications *pend_notify;
|
||||
for (int i = 0; i < ARRAY_SIZE(csip->srv.pend_notify); i++) {
|
||||
struct csip_pending_notifications *pend_notify;
|
||||
|
||||
pend_notify = &csis->srv.pend_notify[i];
|
||||
pend_notify = &csip->srv.pend_notify[i];
|
||||
|
||||
if (!pend_notify->active) {
|
||||
bt_addr_le_copy(&pend_notify->addr,
|
||||
bt_conn_get_dst(conn));
|
||||
pend_notify->active = true;
|
||||
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
|
||||
pend_notify->age = csis->srv.age_counter++;
|
||||
pend_notify->age = csip->srv.age_counter++;
|
||||
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
|
||||
struct csis_pending_notifications *oldest;
|
||||
struct csip_pending_notifications *oldest;
|
||||
|
||||
oldest = &csis->srv.pend_notify[0];
|
||||
oldest = &csip->srv.pend_notify[0];
|
||||
|
||||
for (int i = 1; i < ARRAY_SIZE(csis->srv.pend_notify); i++) {
|
||||
struct csis_pending_notifications *pend_notify;
|
||||
for (int i = 1; i < ARRAY_SIZE(csip->srv.pend_notify); i++) {
|
||||
struct csip_pending_notifications *pend_notify;
|
||||
|
||||
pend_notify = &csis->srv.pend_notify[i];
|
||||
pend_notify = &csip->srv.pend_notify[i];
|
||||
|
||||
if (pend_notify->age < oldest->age) {
|
||||
oldest = pend_notify;
|
||||
|
@ -553,7 +554,7 @@ static void handle_csis_auth_complete(struct bt_csis *csis,
|
|||
(void)memset(oldest, 0, sizeof(*oldest));
|
||||
bt_addr_le_copy(&oldest->addr, &conn->le.dst);
|
||||
oldest->active = true;
|
||||
oldest->age = csis->srv.age_counter++;
|
||||
oldest->age = csip->srv.age_counter++;
|
||||
#else
|
||||
BT_WARN("Could not add device to pending notification list");
|
||||
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
|
||||
|
@ -580,20 +581,20 @@ static void auth_pairing_complete(struct bt_conn *conn, bool bonded)
|
|||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(csis_insts); i++) {
|
||||
handle_csis_auth_complete(&csis_insts[i], conn);
|
||||
for (int i = 0; i < ARRAY_SIZE(csip_insts); i++) {
|
||||
handle_csip_auth_complete(&csip_insts[i], conn);
|
||||
}
|
||||
}
|
||||
|
||||
static void csis_bond_deleted(uint8_t id, const bt_addr_le_t *peer)
|
||||
static void csip_bond_deleted(uint8_t id, const bt_addr_le_t *peer)
|
||||
{
|
||||
for (int i = 0; i < ARRAY_SIZE(csis_insts); i++) {
|
||||
struct bt_csis *csis = &csis_insts[i];
|
||||
for (int i = 0; i < ARRAY_SIZE(csip_insts); i++) {
|
||||
struct bt_csip *csip = &csip_insts[i];
|
||||
|
||||
for (int j = 0; j < ARRAY_SIZE(csis->srv.pend_notify); j++) {
|
||||
struct csis_pending_notifications *pend_notify;
|
||||
for (int j = 0; j < ARRAY_SIZE(csip->srv.pend_notify); j++) {
|
||||
struct csip_pending_notifications *pend_notify;
|
||||
|
||||
pend_notify = &csis->srv.pend_notify[j];
|
||||
pend_notify = &csip->srv.pend_notify[j];
|
||||
|
||||
if (pend_notify->active &&
|
||||
bt_addr_le_eq(peer, &pend_notify->addr)) {
|
||||
|
@ -606,49 +607,49 @@ static void csis_bond_deleted(uint8_t id, const bt_addr_le_t *peer)
|
|||
}
|
||||
|
||||
static struct bt_conn_cb conn_callbacks = {
|
||||
.disconnected = csis_disconnected,
|
||||
.security_changed = csis_security_changed,
|
||||
.disconnected = csip_disconnected,
|
||||
.security_changed = csip_security_changed,
|
||||
};
|
||||
|
||||
static struct bt_conn_auth_info_cb auth_callbacks = {
|
||||
.pairing_complete = auth_pairing_complete,
|
||||
.bond_deleted = csis_bond_deleted
|
||||
.bond_deleted = csip_bond_deleted
|
||||
};
|
||||
|
||||
#define BT_CSIS_SERVICE_DEFINITION(_csis) {\
|
||||
#define BT_CSIP_SERVICE_DEFINITION(_csip) {\
|
||||
BT_GATT_PRIMARY_SERVICE(BT_UUID_CSIS), \
|
||||
BT_AUDIO_CHRC(BT_UUID_CSIS_SET_SIRK, \
|
||||
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
|
||||
BT_GATT_PERM_READ_ENCRYPT, \
|
||||
read_set_sirk, NULL, &_csis), \
|
||||
read_set_sirk, NULL, &_csip), \
|
||||
BT_AUDIO_CCC(set_sirk_cfg_changed), \
|
||||
BT_AUDIO_CHRC(BT_UUID_CSIS_SET_SIZE, \
|
||||
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
|
||||
BT_GATT_PERM_READ_ENCRYPT, \
|
||||
read_set_size, NULL, &_csis), \
|
||||
read_set_size, NULL, &_csip), \
|
||||
BT_AUDIO_CCC(set_size_cfg_changed), \
|
||||
BT_AUDIO_CHRC(BT_UUID_CSIS_SET_LOCK, \
|
||||
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE, \
|
||||
BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT, \
|
||||
read_set_lock, write_set_lock, &_csis), \
|
||||
read_set_lock, write_set_lock, &_csip), \
|
||||
BT_AUDIO_CCC(set_lock_cfg_changed), \
|
||||
BT_AUDIO_CHRC(BT_UUID_CSIS_RANK, \
|
||||
BT_GATT_CHRC_READ, \
|
||||
BT_GATT_PERM_READ_ENCRYPT, \
|
||||
read_rank, NULL, &_csis) \
|
||||
read_rank, NULL, &_csip) \
|
||||
}
|
||||
|
||||
BT_GATT_SERVICE_INSTANCE_DEFINE(csis_service_list, csis_insts,
|
||||
CONFIG_BT_CSIS_MAX_INSTANCE_COUNT,
|
||||
BT_CSIS_SERVICE_DEFINITION);
|
||||
BT_GATT_SERVICE_INSTANCE_DEFINE(csip_service_list, csip_insts,
|
||||
CONFIG_BT_CSIP_MAX_INSTANCE_COUNT,
|
||||
BT_CSIP_SERVICE_DEFINITION);
|
||||
|
||||
/****************************** Public API ******************************/
|
||||
void *bt_csis_svc_decl_get(const struct bt_csis *csis)
|
||||
void *bt_csip_svc_decl_get(const struct bt_csip *csip)
|
||||
{
|
||||
return csis->srv.service_p->attrs;
|
||||
return csip->srv.service_p->attrs;
|
||||
}
|
||||
|
||||
static bool valid_register_param(const struct bt_csis_register_param *param)
|
||||
static bool valid_register_param(const struct bt_csip_register_param *param)
|
||||
{
|
||||
if (param->lockable && param->rank == 0) {
|
||||
BT_DBG("Rank cannot be 0 if service is lockable");
|
||||
|
@ -661,24 +662,24 @@ static bool valid_register_param(const struct bt_csis_register_param *param)
|
|||
return false;
|
||||
}
|
||||
|
||||
#if CONFIG_BT_CSIS_MAX_INSTANCE_COUNT > 1
|
||||
#if CONFIG_BT_CSIP_MAX_INSTANCE_COUNT > 1
|
||||
if (param->parent == NULL) {
|
||||
BT_DBG("Parent service not provided");
|
||||
return false;
|
||||
}
|
||||
#endif /* CONFIG_BT_CSIS_MAX_INSTANCE_COUNT > 1 */
|
||||
#endif /* CONFIG_BT_CSIP_MAX_INSTANCE_COUNT > 1 */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int bt_csis_register(const struct bt_csis_register_param *param,
|
||||
struct bt_csis **csis)
|
||||
int bt_csip_register(const struct bt_csip_register_param *param,
|
||||
struct bt_csip **csip)
|
||||
{
|
||||
static uint8_t instance_cnt;
|
||||
struct bt_csis *inst;
|
||||
struct bt_csip *inst;
|
||||
int err;
|
||||
|
||||
if (instance_cnt == ARRAY_SIZE(csis_insts)) {
|
||||
if (instance_cnt == ARRAY_SIZE(csip_insts)) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
@ -692,8 +693,8 @@ int bt_csis_register(const struct bt_csis_register_param *param,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
inst = &csis_insts[instance_cnt];
|
||||
inst->srv.service_p = &csis_service_list[instance_cnt];
|
||||
inst = &csip_insts[instance_cnt];
|
||||
inst->srv.service_p = &csip_service_list[instance_cnt];
|
||||
instance_cnt++;
|
||||
|
||||
bt_conn_cb_register(&conn_callbacks);
|
||||
|
@ -709,11 +710,11 @@ int bt_csis_register(const struct bt_csis_register_param *param,
|
|||
set_lock_timer_handler);
|
||||
inst->srv.rank = param->rank;
|
||||
inst->srv.set_size = param->set_size;
|
||||
inst->srv.set_lock = BT_CSIS_RELEASE_VALUE;
|
||||
inst->srv.set_sirk.type = BT_CSIS_SIRK_TYPE_PLAIN;
|
||||
inst->srv.set_lock = BT_CSIP_RELEASE_VALUE;
|
||||
inst->srv.set_sirk.type = BT_CSIP_SIRK_TYPE_PLAIN;
|
||||
inst->srv.cb = param->cb;
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_CSIS_TEST_SAMPLE_DATA)) {
|
||||
if (IS_ENABLED(CONFIG_BT_CSIP_TEST_SAMPLE_DATA)) {
|
||||
uint8_t test_sirk[] = {
|
||||
0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce,
|
||||
0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45,
|
||||
|
@ -721,36 +722,36 @@ int bt_csis_register(const struct bt_csis_register_param *param,
|
|||
|
||||
(void)memcpy(inst->srv.set_sirk.value, test_sirk,
|
||||
sizeof(test_sirk));
|
||||
BT_DBG("CSIS SIRK was overwritten by sample data SIRK");
|
||||
BT_DBG("CSIP SIRK was overwritten by sample data SIRK");
|
||||
} else {
|
||||
(void)memcpy(inst->srv.set_sirk.value, param->set_sirk,
|
||||
sizeof(inst->srv.set_sirk.value));
|
||||
}
|
||||
|
||||
*csis = inst;
|
||||
*csip = inst;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_csis_lock(struct bt_csis *csis, bool lock, bool force)
|
||||
int bt_csip_lock(struct bt_csip *csip, bool lock, bool force)
|
||||
{
|
||||
uint8_t lock_val;
|
||||
int err = 0;
|
||||
|
||||
if (lock) {
|
||||
lock_val = BT_CSIS_LOCK_VALUE;
|
||||
lock_val = BT_CSIP_LOCK_VALUE;
|
||||
} else {
|
||||
lock_val = BT_CSIS_RELEASE_VALUE;
|
||||
lock_val = BT_CSIP_RELEASE_VALUE;
|
||||
}
|
||||
|
||||
if (!lock && force) {
|
||||
csis->srv.set_lock = BT_CSIS_RELEASE_VALUE;
|
||||
notify_clients(csis, NULL);
|
||||
csip->srv.set_lock = BT_CSIP_RELEASE_VALUE;
|
||||
notify_clients(csip, NULL);
|
||||
|
||||
if (csis->srv.cb != NULL && csis->srv.cb->lock_changed != NULL) {
|
||||
csis->srv.cb->lock_changed(NULL, &csis_insts[0], false);
|
||||
if (csip->srv.cb != NULL && csip->srv.cb->lock_changed != NULL) {
|
||||
csip->srv.cb->lock_changed(NULL, &csip_insts[0], false);
|
||||
}
|
||||
} else {
|
||||
err = set_lock(NULL, csis, lock_val);
|
||||
err = set_lock(NULL, csip, lock_val);
|
||||
}
|
||||
|
||||
if (err < 0) {
|
||||
|
@ -760,7 +761,8 @@ int bt_csis_lock(struct bt_csis *csis, bool lock, bool force)
|
|||
}
|
||||
}
|
||||
|
||||
void bt_csis_print_sirk(const struct bt_csis *csis)
|
||||
void bt_csip_print_sirk(const struct bt_csip *csip)
|
||||
{
|
||||
LOG_HEXDUMP_DBG(&csis->srv.set_sirk, sizeof(csis->srv.set_sirk), "Set SIRK");
|
||||
LOG_HEXDUMP_DBG(&csip->srv.set_sirk, sizeof(csip->srv.set_sirk),
|
||||
"Set SIRK");
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Bose Corporation
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2021-2022 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
@ -9,7 +9,7 @@
|
|||
* in the CSIS spec is also provided as BE, and logging values as BE will make
|
||||
* it easier to compare.
|
||||
*/
|
||||
#include "csis_crypto.h"
|
||||
#include "csip_crypto.h"
|
||||
#include <zephyr/bluetooth/crypto.h>
|
||||
#include <tinycrypt/constants.h>
|
||||
#include <tinycrypt/utils.h>
|
||||
|
@ -18,16 +18,16 @@
|
|||
#include <tinycrypt/ccm_mode.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIS_CRYPTO)
|
||||
#define LOG_MODULE_NAME bt_csis_crypto
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_CSIP_CRYPTO)
|
||||
#define LOG_MODULE_NAME bt_csip_crypto
|
||||
#include "common/log.h"
|
||||
#include "common/bt_str.h"
|
||||
|
||||
#define BT_CSIS_CRYPTO_PADDING_SIZE 13
|
||||
#define BT_CSIS_R_SIZE 3 /* r is 24 bit / 3 octet */
|
||||
#define BT_CSIS_R_MASK BIT_MASK(24) /* r is 24 bit / 3 octet */
|
||||
#define BT_CSIP_CRYPTO_PADDING_SIZE 13
|
||||
#define BT_CSIP_R_SIZE 3 /* r is 24 bit / 3 octet */
|
||||
#define BT_CSIP_R_MASK BIT_MASK(24) /* r is 24 bit / 3 octet */
|
||||
|
||||
static int aes_cmac(const uint8_t key[BT_CSIS_CRYPTO_KEY_SIZE],
|
||||
static int aes_cmac(const uint8_t key[BT_CSIP_CRYPTO_KEY_SIZE],
|
||||
const uint8_t *in, size_t in_len, uint8_t *out)
|
||||
{
|
||||
struct tc_aes_key_sched_struct sched;
|
||||
|
@ -60,31 +60,31 @@ static void xor_128(const uint8_t a[16], const uint8_t b[16], uint8_t out[16])
|
|||
}
|
||||
}
|
||||
|
||||
int bt_csis_sih(const uint8_t sirk[BT_CSIS_SET_SIRK_SIZE], uint32_t r,
|
||||
int bt_csip_sih(const uint8_t sirk[BT_CSIP_SET_SIRK_SIZE], uint32_t r,
|
||||
uint32_t *out)
|
||||
{
|
||||
uint8_t res[16]; /* need to store 128 bit */
|
||||
int err;
|
||||
uint8_t sirk_tmp[BT_CSIS_SET_SIRK_SIZE];
|
||||
uint8_t sirk_tmp[BT_CSIP_SET_SIRK_SIZE];
|
||||
|
||||
if ((r & BIT(23)) || ((r & BIT(22)) == 0)) {
|
||||
BT_DBG("Invalid r %0x06x", (uint32_t)(r & BT_CSIS_R_MASK));
|
||||
BT_DBG("Invalid r %0x06x", (uint32_t)(r & BT_CSIP_R_MASK));
|
||||
}
|
||||
|
||||
BT_DBG("SIRK %s", bt_hex(sirk, BT_CSIS_SET_SIRK_SIZE));
|
||||
BT_DBG("SIRK %s", bt_hex(sirk, BT_CSIP_SET_SIRK_SIZE));
|
||||
BT_DBG("r 0x%06x", r);
|
||||
|
||||
/* r' = padding || r */
|
||||
(void)memset(res, 0, BT_CSIS_CRYPTO_PADDING_SIZE);
|
||||
sys_put_be24(r, res + BT_CSIS_CRYPTO_PADDING_SIZE);
|
||||
(void)memset(res, 0, BT_CSIP_CRYPTO_PADDING_SIZE);
|
||||
sys_put_be24(r, res + BT_CSIP_CRYPTO_PADDING_SIZE);
|
||||
|
||||
BT_DBG("BE: r' %s", bt_hex(res, sizeof(res)));
|
||||
|
||||
if (IS_ENABLED(CONFIG_LITTLE_ENDIAN)) {
|
||||
/* Swap to Big Endian (BE) */
|
||||
sys_memcpy_swap(sirk_tmp, sirk, BT_CSIS_SET_SIRK_SIZE);
|
||||
sys_memcpy_swap(sirk_tmp, sirk, BT_CSIP_SET_SIRK_SIZE);
|
||||
} else {
|
||||
(void)memcpy(sirk_tmp, sirk, BT_CSIS_SET_SIRK_SIZE);
|
||||
(void)memcpy(sirk_tmp, sirk, BT_CSIP_SET_SIRK_SIZE);
|
||||
}
|
||||
|
||||
err = bt_encrypt_be(sirk_tmp, res, res);
|
||||
|
@ -126,7 +126,7 @@ int bt_csis_sih(const uint8_t sirk[BT_CSIS_SET_SIRK_SIZE], uint32_t r,
|
|||
* @return int 0 on success, any other value indicates a failure.
|
||||
*/
|
||||
static int k1(const uint8_t *n, size_t n_size,
|
||||
const uint8_t salt[BT_CSIS_CRYPTO_SALT_SIZE],
|
||||
const uint8_t salt[BT_CSIP_CRYPTO_SALT_SIZE],
|
||||
const uint8_t *p, size_t p_size, uint8_t out[16])
|
||||
{
|
||||
/* TODO: This is basically a duplicate of bt_mesh_k1 - Perhaps they can
|
||||
|
@ -142,7 +142,7 @@ static int k1(const uint8_t *n, size_t n_size,
|
|||
*/
|
||||
|
||||
BT_DBG("BE: n %s", bt_hex(n, n_size));
|
||||
BT_DBG("BE: salt %s", bt_hex(salt, BT_CSIS_CRYPTO_SALT_SIZE));
|
||||
BT_DBG("BE: salt %s", bt_hex(salt, BT_CSIP_CRYPTO_SALT_SIZE));
|
||||
BT_DBG("BE: p %s", bt_hex(p, p_size));
|
||||
|
||||
err = aes_cmac(salt, n, n_size, t);
|
||||
|
@ -169,7 +169,7 @@ static int k1(const uint8_t *n, size_t n_size,
|
|||
* @return int 0 on success, any other value indicates a failure.
|
||||
*/
|
||||
static int s1(const uint8_t *m, size_t m_size,
|
||||
uint8_t out[BT_CSIS_CRYPTO_SALT_SIZE])
|
||||
uint8_t out[BT_CSIP_CRYPTO_SALT_SIZE])
|
||||
{
|
||||
uint8_t zero[16];
|
||||
int err;
|
||||
|
@ -189,22 +189,22 @@ static int s1(const uint8_t *m, size_t m_size,
|
|||
return err;
|
||||
}
|
||||
|
||||
int bt_csis_sef(const uint8_t k[BT_CSIS_CRYPTO_KEY_SIZE],
|
||||
const uint8_t sirk[BT_CSIS_SET_SIRK_SIZE],
|
||||
uint8_t out_sirk[BT_CSIS_SET_SIRK_SIZE])
|
||||
int bt_csip_sef(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE],
|
||||
const uint8_t sirk[BT_CSIP_SET_SIRK_SIZE],
|
||||
uint8_t out_sirk[BT_CSIP_SET_SIRK_SIZE])
|
||||
{
|
||||
const uint8_t m[] = {'S', 'I', 'R', 'K', 'e', 'n', 'c'};
|
||||
const uint8_t p[] = {'c', 's', 'i', 's'};
|
||||
uint8_t s1_out[BT_CSIS_CRYPTO_SALT_SIZE];
|
||||
uint8_t k1_out[BT_CSIS_CRYPTO_KEY_SIZE];
|
||||
uint8_t k1_tmp[BT_CSIS_CRYPTO_KEY_SIZE];
|
||||
uint8_t s1_out[BT_CSIP_CRYPTO_SALT_SIZE];
|
||||
uint8_t k1_out[BT_CSIP_CRYPTO_KEY_SIZE];
|
||||
uint8_t k1_tmp[BT_CSIP_CRYPTO_KEY_SIZE];
|
||||
int err;
|
||||
|
||||
/*
|
||||
* sef(K, SIRK) = k1(K, s1("SIRKenc"), "csis") ^ SIRK
|
||||
*/
|
||||
|
||||
BT_DBG("SIRK %s", bt_hex(sirk, BT_CSIS_SET_SIRK_SIZE));
|
||||
BT_DBG("SIRK %s", bt_hex(sirk, BT_CSIP_SET_SIRK_SIZE));
|
||||
|
||||
if (IS_ENABLED(CONFIG_LITTLE_ENDIAN)) {
|
||||
/* Swap because aes_cmac is big endian
|
||||
|
@ -236,14 +236,14 @@ int bt_csis_sef(const uint8_t k[BT_CSIS_CRYPTO_KEY_SIZE],
|
|||
}
|
||||
|
||||
xor_128(k1_out, sirk, out_sirk);
|
||||
BT_DBG("out %s", bt_hex(out_sirk, BT_CSIS_SET_SIRK_SIZE));
|
||||
BT_DBG("out %s", bt_hex(out_sirk, BT_CSIP_SET_SIRK_SIZE));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_csis_sdf(const uint8_t k[BT_CSIS_CRYPTO_KEY_SIZE],
|
||||
const uint8_t enc_sirk[BT_CSIS_SET_SIRK_SIZE],
|
||||
uint8_t out_sirk[BT_CSIS_SET_SIRK_SIZE])
|
||||
int bt_csip_sdf(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE],
|
||||
const uint8_t enc_sirk[BT_CSIP_SET_SIRK_SIZE],
|
||||
uint8_t out_sirk[BT_CSIP_SET_SIRK_SIZE])
|
||||
{
|
||||
/* SIRK encryption is currently symmetric, which means that we can
|
||||
* simply apply the sef function to decrypt it.
|
||||
|
@ -254,5 +254,5 @@ int bt_csis_sdf(const uint8_t k[BT_CSIS_CRYPTO_KEY_SIZE],
|
|||
*/
|
||||
|
||||
BT_DBG("Running SDF as SEF");
|
||||
return bt_csis_sef(k, enc_sirk, out_sirk);
|
||||
return bt_csip_sef(k, enc_sirk, out_sirk);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Bose Corporation
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2021-2022 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -8,10 +8,10 @@
|
|||
#include <stddef.h>
|
||||
#include <zephyr/types.h>
|
||||
|
||||
#include <zephyr/bluetooth/audio/csis.h>
|
||||
#include <zephyr/bluetooth/audio/csip.h>
|
||||
|
||||
#define BT_CSIS_CRYPTO_KEY_SIZE 16
|
||||
#define BT_CSIS_CRYPTO_SALT_SIZE 16
|
||||
#define BT_CSIP_CRYPTO_KEY_SIZE 16
|
||||
#define BT_CSIP_CRYPTO_SALT_SIZE 16
|
||||
|
||||
/**
|
||||
* @brief Private Set Unique identifier hash function sih.
|
||||
|
@ -25,7 +25,7 @@
|
|||
* @param out The 3 byte output buffer
|
||||
* @return int 0 on success, any other value indicates a failure.
|
||||
*/
|
||||
int bt_csis_sih(const uint8_t sirk[BT_CSIS_SET_SIRK_SIZE], uint32_t r,
|
||||
int bt_csip_sih(const uint8_t sirk[BT_CSIP_SET_SIRK_SIZE], uint32_t r,
|
||||
uint32_t *out);
|
||||
|
||||
/**
|
||||
|
@ -51,9 +51,9 @@ int bt_csis_sih(const uint8_t sirk[BT_CSIS_SET_SIRK_SIZE], uint32_t r,
|
|||
* @param out_sirk The encrypted SIRK.
|
||||
* @return int 0 on success, any other value indicates a failure.
|
||||
*/
|
||||
int bt_csis_sef(const uint8_t k[BT_CSIS_CRYPTO_KEY_SIZE],
|
||||
const uint8_t sirk[BT_CSIS_SET_SIRK_SIZE],
|
||||
uint8_t out_sirk[BT_CSIS_SET_SIRK_SIZE]);
|
||||
int bt_csip_sef(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE],
|
||||
const uint8_t sirk[BT_CSIP_SET_SIRK_SIZE],
|
||||
uint8_t out_sirk[BT_CSIP_SET_SIRK_SIZE]);
|
||||
|
||||
/**
|
||||
* @brief SIRK decryption function sdf
|
||||
|
@ -78,6 +78,6 @@ int bt_csis_sef(const uint8_t k[BT_CSIS_CRYPTO_KEY_SIZE],
|
|||
* @param out_sirk The decrypted SIRK.
|
||||
* @return int 0 on success, any other value indicates a failure.
|
||||
*/
|
||||
int bt_csis_sdf(const uint8_t k[BT_CSIS_CRYPTO_KEY_SIZE],
|
||||
const uint8_t enc_sirk[BT_CSIS_SET_SIRK_SIZE],
|
||||
uint8_t out_sirk[BT_CSIS_SET_SIRK_SIZE]);
|
||||
int bt_csip_sdf(const uint8_t k[BT_CSIP_CRYPTO_KEY_SIZE],
|
||||
const uint8_t enc_sirk[BT_CSIP_SET_SIRK_SIZE],
|
||||
uint8_t out_sirk[BT_CSIP_SET_SIRK_SIZE]);
|
|
@ -1,22 +1,22 @@
|
|||
/**
|
||||
* @file
|
||||
* @brief Internal APIs for Bluetooth CSIS
|
||||
* @brief Internal APIs for Bluetooth CSIP
|
||||
*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2021-2022 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/bluetooth/audio/csis.h>
|
||||
#include <zephyr/bluetooth/audio/csip.h>
|
||||
|
||||
|
||||
#define BT_CSIS_SIRK_TYPE_ENCRYPTED 0x00
|
||||
#define BT_CSIS_SIRK_TYPE_PLAIN 0x01
|
||||
#define BT_CSIP_SIRK_TYPE_ENCRYPTED 0x00
|
||||
#define BT_CSIP_SIRK_TYPE_PLAIN 0x01
|
||||
|
||||
#define BT_CSIS_RELEASE_VALUE 0x01
|
||||
#define BT_CSIS_LOCK_VALUE 0x02
|
||||
#define BT_CSIP_RELEASE_VALUE 0x01
|
||||
#define BT_CSIP_LOCK_VALUE 0x02
|
||||
|
||||
struct csis_pending_notifications {
|
||||
struct csip_pending_notifications {
|
||||
bt_addr_le_t addr;
|
||||
bool pending;
|
||||
bool active;
|
||||
|
@ -30,12 +30,12 @@ struct csis_pending_notifications {
|
|||
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
|
||||
};
|
||||
|
||||
struct bt_csis_set_sirk {
|
||||
struct bt_csip_set_sirk {
|
||||
uint8_t type;
|
||||
uint8_t value[BT_CSIS_SET_SIRK_SIZE];
|
||||
uint8_t value[BT_CSIP_SET_SIRK_SIZE];
|
||||
} __packed;
|
||||
|
||||
struct bt_csis_client_svc_inst {
|
||||
struct bt_csip_set_coordinator_svc_inst {
|
||||
uint8_t rank;
|
||||
uint8_t set_lock;
|
||||
|
||||
|
@ -55,36 +55,36 @@ struct bt_csis_client_svc_inst {
|
|||
struct bt_gatt_discover_params lock_sub_disc_params;
|
||||
|
||||
struct bt_conn *conn;
|
||||
struct bt_csis_client_set_member *member;
|
||||
struct bt_csip_set_coordinator_set_member *member;
|
||||
};
|
||||
|
||||
/* TODO: Rename to bt_csis_svc_inst */
|
||||
struct bt_csis_server {
|
||||
struct bt_csis_set_sirk set_sirk;
|
||||
/* TODO: Rename to bt_csip_svc_inst */
|
||||
struct bt_csip_server {
|
||||
struct bt_csip_set_sirk set_sirk;
|
||||
uint8_t set_size;
|
||||
uint8_t set_lock;
|
||||
uint8_t rank;
|
||||
struct bt_csis_cb *cb;
|
||||
struct bt_csip_cb *cb;
|
||||
struct k_work_delayable set_lock_timer;
|
||||
bt_addr_le_t lock_client_addr;
|
||||
struct bt_gatt_service *service_p;
|
||||
struct csis_pending_notifications pend_notify[CONFIG_BT_MAX_PAIRED];
|
||||
struct csip_pending_notifications pend_notify[CONFIG_BT_MAX_PAIRED];
|
||||
#if IS_ENABLED(CONFIG_BT_KEYS_OVERWRITE_OLDEST)
|
||||
uint32_t age_counter;
|
||||
#endif /* CONFIG_BT_KEYS_OVERWRITE_OLDEST */
|
||||
};
|
||||
|
||||
struct bt_csis {
|
||||
struct bt_csip {
|
||||
bool client_instance;
|
||||
union {
|
||||
#if defined(CONFIG_BT_CSIS)
|
||||
struct bt_csis_server srv;
|
||||
#endif /* CONFIG_BT_CSIS */
|
||||
#if defined(CONFIG_BT_CSIS_CLIENT)
|
||||
struct bt_csis_client_svc_inst cli;
|
||||
#endif /* CONFIG_BT_CSIS_CLIENT */
|
||||
#if defined(CONFIG_BT_CSIP)
|
||||
struct bt_csip_server srv;
|
||||
#endif /* CONFIG_BT_CSIP */
|
||||
#if defined(CONFIG_BT_CSIP_SET_COORDINATOR)
|
||||
struct bt_csip_set_coordinator_svc_inst cli;
|
||||
#endif /* CONFIG_BT_CSIP_SET_COORDINATOR */
|
||||
};
|
||||
};
|
||||
|
||||
struct bt_csis_client_csis_inst *bt_csis_client_csis_inst_by_handle(struct bt_conn *conn,
|
||||
uint16_t start_handle);
|
||||
struct bt_csip_set_coordinator_csis_inst *bt_csip_set_coordinator_csis_inst_by_handle(
|
||||
struct bt_conn *conn, uint16_t start_handle);
|
File diff suppressed because it is too large
Load diff
|
@ -42,12 +42,12 @@ zephyr_library_sources_ifdef(
|
|||
micp_mic_ctlr.c
|
||||
)
|
||||
zephyr_library_sources_ifdef(
|
||||
CONFIG_BT_CSIS
|
||||
csis.c
|
||||
CONFIG_BT_CSIP
|
||||
csip.c
|
||||
)
|
||||
zephyr_library_sources_ifdef(
|
||||
CONFIG_BT_CSIS_CLIENT
|
||||
csis_client.c
|
||||
CONFIG_BT_CSIP_SET_COORDINATOR
|
||||
csip_set_coordinator.c
|
||||
)
|
||||
zephyr_library_sources_ifdef(
|
||||
CONFIG_BT_TBS
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <zephyr/bluetooth/iso.h>
|
||||
#include <zephyr/bluetooth/audio/audio.h>
|
||||
#include <zephyr/bluetooth/audio/pacs.h>
|
||||
#include <zephyr/bluetooth/audio/csis.h>
|
||||
#include <zephyr/bluetooth/audio/csip.h>
|
||||
|
||||
#include <zephyr/shell/shell.h>
|
||||
|
||||
|
@ -1245,7 +1245,7 @@ static ssize_t ad_init(struct bt_data *data_array, const size_t data_array_size,
|
|||
/* A privacy-enabled Set Member should advertise RSI values only when in
|
||||
* the GAP Limited Discoverable mode.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_BT_PRIVACY) && IS_ENABLED(CONFIG_BT_CSIS) && csis != NULL) {
|
||||
if (IS_ENABLED(CONFIG_BT_PRIVACY) && IS_ENABLED(CONFIG_BT_CSIP) && csip != NULL) {
|
||||
ad_flags |= BT_LE_AD_LIMITED;
|
||||
} else {
|
||||
ad_flags |= BT_LE_AD_GENERAL;
|
||||
|
@ -1272,7 +1272,7 @@ static ssize_t ad_init(struct bt_data *data_array, const size_t data_array_size,
|
|||
ad_len++;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_CSIS)) {
|
||||
if (IS_ENABLED(CONFIG_BT_CSIP)) {
|
||||
ssize_t csis_ad_len;
|
||||
|
||||
csis_ad_len = csis_ad_data_add(&data_array[ad_len],
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
extern const struct shell *ctx_shell;
|
||||
extern struct bt_conn *default_conn;
|
||||
extern struct bt_csis *csis;
|
||||
extern struct bt_csip *csip;
|
||||
|
||||
#if defined(CONFIG_BT_ISO)
|
||||
extern struct bt_iso_chan iso_chan;
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
#include "bt.h"
|
||||
|
||||
extern const struct shell *ctx_shell;
|
||||
static struct bt_csis *cap_csis;
|
||||
static uint8_t sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT;
|
||||
static struct bt_csip *cap_csip;
|
||||
static uint8_t sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT;
|
||||
|
||||
static void locked_cb(struct bt_conn *conn, struct bt_csis *csis, bool locked)
|
||||
static void locked_cb(struct bt_conn *conn, struct bt_csip *csip, bool locked)
|
||||
{
|
||||
if (conn == NULL) {
|
||||
shell_error(ctx_shell, "Server %s the device",
|
||||
|
@ -34,7 +34,7 @@ static void locked_cb(struct bt_conn *conn, struct bt_csis *csis, bool locked)
|
|||
}
|
||||
}
|
||||
|
||||
static uint8_t sirk_read_req_cb(struct bt_conn *conn, struct bt_csis *csis)
|
||||
static uint8_t sirk_read_req_cb(struct bt_conn *conn, struct bt_csip *csip)
|
||||
{
|
||||
char addr[BT_ADDR_LE_STR_LEN];
|
||||
static const char *const rsp_strings[] = {
|
||||
|
@ -49,7 +49,7 @@ static uint8_t sirk_read_req_cb(struct bt_conn *conn, struct bt_csis *csis)
|
|||
return sirk_read_rsp;
|
||||
}
|
||||
|
||||
static struct bt_csis_cb csis_cbs = {
|
||||
static struct bt_csip_cb csip_cbs = {
|
||||
.lock_changed = locked_cb,
|
||||
.sirk_read_req = sirk_read_req_cb,
|
||||
};
|
||||
|
@ -58,14 +58,14 @@ static int cmd_cap_acceptor_init(const struct shell *sh, size_t argc,
|
|||
char **argv)
|
||||
{
|
||||
int err;
|
||||
struct bt_csis_register_param param = {
|
||||
struct bt_csip_register_param param = {
|
||||
.set_size = 2,
|
||||
.rank = 1,
|
||||
.lockable = true,
|
||||
/* Using the CSIS test sample SIRK */
|
||||
.set_sirk = { 0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce,
|
||||
0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 },
|
||||
.cb = &csis_cbs
|
||||
.cb = &csip_cbs
|
||||
};
|
||||
|
||||
for (size_t argn = 1; argn < argc; argn++) {
|
||||
|
@ -95,7 +95,7 @@ static int cmd_cap_acceptor_init(const struct shell *sh, size_t argc,
|
|||
}
|
||||
}
|
||||
|
||||
err = bt_cap_acceptor_register(¶m, &cap_csis);
|
||||
err = bt_cap_acceptor_register(¶m, &cap_csip);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Could not register CAS: %d", err);
|
||||
|
||||
|
@ -108,7 +108,7 @@ static int cmd_cap_acceptor_init(const struct shell *sh, size_t argc,
|
|||
static int cmd_cap_acceptor_print_sirk(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
{
|
||||
bt_csis_print_sirk(cap_csis);
|
||||
bt_csip_print_sirk(cap_csip);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ static int cmd_cap_acceptor_lock(const struct shell *sh, size_t argc,
|
|||
{
|
||||
int err;
|
||||
|
||||
err = bt_csis_lock(cap_csis, true, false);
|
||||
err = bt_csip_lock(cap_csip, true, false);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Failed to set lock: %d", err);
|
||||
|
||||
|
@ -146,7 +146,7 @@ static int cmd_cap_acceptor_release(const struct shell *sh, size_t argc,
|
|||
}
|
||||
}
|
||||
|
||||
err = bt_csis_lock(cap_csis, false, force);
|
||||
err = bt_csip_lock(cap_csip, false, force);
|
||||
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Failed to release lock: %d", err);
|
||||
|
@ -163,13 +163,13 @@ static int cmd_cap_acceptor_set_sirk_rsp(const struct shell *sh, size_t argc,
|
|||
char *argv[])
|
||||
{
|
||||
if (strcmp(argv[1], "accept") == 0) {
|
||||
sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT;
|
||||
sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT;
|
||||
} else if (strcmp(argv[1], "accept_enc") == 0) {
|
||||
sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT_ENC;
|
||||
sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT_ENC;
|
||||
} else if (strcmp(argv[1], "reject") == 0) {
|
||||
sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_REJECT;
|
||||
sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_REJECT;
|
||||
} else if (strcmp(argv[1], "oob") == 0) {
|
||||
sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_OOB_ONLY;
|
||||
sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_OOB_ONLY;
|
||||
} else {
|
||||
shell_error(sh, "Unknown parameter: %s", argv[1]);
|
||||
return -ENOEXEC;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#if defined(CONFIG_BT_AUDIO_UNICAST_CLIENT)
|
||||
|
||||
static void cap_discover_cb(struct bt_conn *conn, int err,
|
||||
const struct bt_csis_client_csis_inst *csis_inst)
|
||||
const struct bt_csip_set_coordinator_csis_inst *csis_inst)
|
||||
{
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "discover failed (%d)", err);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* @file
|
||||
* @brief Shell APIs for Bluetooth CSIS
|
||||
* @brief Shell APIs for Bluetooth CSIP
|
||||
*
|
||||
* Copyright (c) 2020 Bose Corporation
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
|
@ -16,14 +16,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <zephyr/bluetooth/gatt.h>
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/bluetooth/audio/csis.h>
|
||||
#include <zephyr/bluetooth/audio/csip.h>
|
||||
#include "bt.h"
|
||||
|
||||
extern const struct shell *ctx_shell;
|
||||
struct bt_csis *csis;
|
||||
static uint8_t sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT;
|
||||
struct bt_csip *csip;
|
||||
static uint8_t sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT;
|
||||
|
||||
static void locked_cb(struct bt_conn *conn, struct bt_csis *csis, bool locked)
|
||||
static void locked_cb(struct bt_conn *conn, struct bt_csip *csip, bool locked)
|
||||
{
|
||||
if (conn == NULL) {
|
||||
shell_error(ctx_shell, "Server %s the device",
|
||||
|
@ -38,7 +38,7 @@ static void locked_cb(struct bt_conn *conn, struct bt_csis *csis, bool locked)
|
|||
}
|
||||
}
|
||||
|
||||
static uint8_t sirk_read_req_cb(struct bt_conn *conn, struct bt_csis *csis)
|
||||
static uint8_t sirk_read_req_cb(struct bt_conn *conn, struct bt_csip *csip)
|
||||
{
|
||||
char addr[BT_ADDR_LE_STR_LEN];
|
||||
static const char *const rsp_strings[] = {
|
||||
|
@ -53,22 +53,22 @@ static uint8_t sirk_read_req_cb(struct bt_conn *conn, struct bt_csis *csis)
|
|||
return sirk_read_rsp;
|
||||
}
|
||||
|
||||
static struct bt_csis_cb csis_cbs = {
|
||||
static struct bt_csip_cb csip_cbs = {
|
||||
.lock_changed = locked_cb,
|
||||
.sirk_read_req = sirk_read_req_cb,
|
||||
};
|
||||
|
||||
static int cmd_csis_register(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_csip_register(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
int err;
|
||||
struct bt_csis_register_param param = {
|
||||
struct bt_csip_register_param param = {
|
||||
.set_size = 2,
|
||||
.rank = 1,
|
||||
.lockable = true,
|
||||
/* Using the CSIS test sample SIRK */
|
||||
.set_sirk = { 0xcd, 0xcc, 0x72, 0xdd, 0x86, 0x8c, 0xcd, 0xce,
|
||||
0x22, 0xfd, 0xa1, 0x21, 0x09, 0x7d, 0x7d, 0x45 },
|
||||
.cb = &csis_cbs
|
||||
.cb = &csip_cbs
|
||||
};
|
||||
|
||||
for (size_t argn = 1; argn < argc; argn++) {
|
||||
|
@ -96,27 +96,27 @@ static int cmd_csis_register(const struct shell *sh, size_t argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
err = bt_csis_register(¶m, &csis);
|
||||
err = bt_csip_register(¶m, &csip);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Could not register CSIS: %d", err);
|
||||
shell_error(sh, "Could not register CSIP: %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_csis_print_sirk(const struct shell *sh, size_t argc,
|
||||
static int cmd_csip_print_sirk(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
{
|
||||
bt_csis_print_sirk(csis);
|
||||
bt_csip_print_sirk(csip);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_csis_lock(const struct shell *sh, size_t argc, char *argv[])
|
||||
static int cmd_csip_lock(const struct shell *sh, size_t argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
err = bt_csis_lock(csis, true, false);
|
||||
err = bt_csip_lock(csip, true, false);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Failed to set lock: %d", err);
|
||||
return -ENOEXEC;
|
||||
|
@ -127,7 +127,7 @@ static int cmd_csis_lock(const struct shell *sh, size_t argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_csis_release(const struct shell *sh, size_t argc,
|
||||
static int cmd_csip_release(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
{
|
||||
bool force = false;
|
||||
|
@ -142,7 +142,7 @@ static int cmd_csis_release(const struct shell *sh, size_t argc,
|
|||
}
|
||||
}
|
||||
|
||||
err = bt_csis_lock(csis, false, force);
|
||||
err = bt_csip_lock(csip, false, force);
|
||||
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Failed to release lock: %d", err);
|
||||
|
@ -154,17 +154,17 @@ static int cmd_csis_release(const struct shell *sh, size_t argc,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_csis_set_sirk_rsp(const struct shell *sh, size_t argc,
|
||||
static int cmd_csip_set_sirk_rsp(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
{
|
||||
if (strcmp(argv[1], "accept") == 0) {
|
||||
sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT;
|
||||
sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT;
|
||||
} else if (strcmp(argv[1], "accept_enc") == 0) {
|
||||
sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT_ENC;
|
||||
sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_ACCEPT_ENC;
|
||||
} else if (strcmp(argv[1], "reject") == 0) {
|
||||
sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_REJECT;
|
||||
sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_REJECT;
|
||||
} else if (strcmp(argv[1], "oob") == 0) {
|
||||
sirk_read_rsp = BT_CSIS_READ_SIRK_REQ_RSP_OOB_ONLY;
|
||||
sirk_read_rsp = BT_CSIP_READ_SIRK_REQ_RSP_OOB_ONLY;
|
||||
} else {
|
||||
shell_error(sh, "Unknown parameter: %s", argv[1]);
|
||||
return -ENOEXEC;
|
||||
|
@ -173,36 +173,36 @@ static int cmd_csis_set_sirk_rsp(const struct shell *sh, size_t argc,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_csis(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_csip(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
shell_error(sh, "%s unknown parameter: %s", argv[0], argv[1]);
|
||||
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(csis_cmds,
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(csip_cmds,
|
||||
SHELL_CMD_ARG(register, NULL,
|
||||
"Initialize the service and register callbacks "
|
||||
"[size <int>] [rank <int>] [not-lockable] [sirk <data>]",
|
||||
cmd_csis_register, 1, 4),
|
||||
cmd_csip_register, 1, 4),
|
||||
SHELL_CMD_ARG(lock, NULL,
|
||||
"Lock the set",
|
||||
cmd_csis_lock, 1, 0),
|
||||
cmd_csip_lock, 1, 0),
|
||||
SHELL_CMD_ARG(release, NULL,
|
||||
"Release the set [force]",
|
||||
cmd_csis_release, 1, 1),
|
||||
cmd_csip_release, 1, 1),
|
||||
SHELL_CMD_ARG(print_sirk, NULL,
|
||||
"Print the currently used SIRK",
|
||||
cmd_csis_print_sirk, 1, 0),
|
||||
cmd_csip_print_sirk, 1, 0),
|
||||
SHELL_CMD_ARG(set_sirk_rsp, NULL,
|
||||
"Set the response used in SIRK requests "
|
||||
"<accept, accept_enc, reject, oob>",
|
||||
cmd_csis_set_sirk_rsp, 2, 0),
|
||||
cmd_csip_set_sirk_rsp, 2, 0),
|
||||
SHELL_SUBCMD_SET_END
|
||||
);
|
||||
|
||||
SHELL_CMD_ARG_REGISTER(csis, &csis_cmds, "Bluetooth CSIS shell commands",
|
||||
cmd_csis, 1, 1);
|
||||
SHELL_CMD_ARG_REGISTER(csip, &csip_cmds, "Bluetooth CSIP shell commands",
|
||||
cmd_csip, 1, 1);
|
||||
|
||||
ssize_t csis_ad_data_add(struct bt_data *data_array, const size_t data_array_size,
|
||||
const bool discoverable)
|
||||
|
@ -210,19 +210,19 @@ ssize_t csis_ad_data_add(struct bt_data *data_array, const size_t data_array_siz
|
|||
size_t ad_len = 0;
|
||||
|
||||
/* Advertise RSI in discoverable mode only */
|
||||
if (csis != NULL && discoverable) {
|
||||
static uint8_t ad_rsi[BT_CSIS_RSI_SIZE];
|
||||
if (csip != NULL && discoverable) {
|
||||
static uint8_t ad_rsi[BT_CSIP_RSI_SIZE];
|
||||
int err;
|
||||
|
||||
/* A privacy-enabled Set Member should only advertise RSI values derived
|
||||
* from a SIRK that is exposed in encrypted form.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_BT_PRIVACY) &&
|
||||
!IS_ENABLED(CONFIG_BT_CSIS_ENC_SIRK_SUPPORT)) {
|
||||
!IS_ENABLED(CONFIG_BT_CSIP_ENC_SIRK_SUPPORT)) {
|
||||
shell_warn(ctx_shell, "RSI derived from unencrypted SIRK");
|
||||
}
|
||||
|
||||
err = bt_csis_generate_rsi(csis, ad_rsi);
|
||||
err = bt_csip_generate_rsi(csip, ad_rsi);
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "Failed to generate RSI (err %d)", err);
|
||||
return err;
|
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* @file
|
||||
* @brief Shell APIs for Bluetooth CSIS client
|
||||
* @brief Shell APIs for Bluetooth CSIP set coordinator
|
||||
*
|
||||
* Copyright (c) 2020 Bose Corporation
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2021-2022 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -20,15 +20,15 @@
|
|||
|
||||
#include "bt.h"
|
||||
|
||||
#include <zephyr/bluetooth/audio/csis.h>
|
||||
#include <zephyr/bluetooth/audio/csip.h>
|
||||
|
||||
static uint8_t members_found;
|
||||
static struct k_work_delayable discover_members_timer;
|
||||
static struct bt_conn *conns[CONFIG_BT_MAX_CONN];
|
||||
static const struct bt_csis_client_set_member *set_members[CONFIG_BT_MAX_CONN];
|
||||
struct bt_csis_client_csis_inst *cur_inst;
|
||||
static const struct bt_csip_set_coordinator_set_member *set_members[CONFIG_BT_MAX_CONN];
|
||||
struct bt_csip_set_coordinator_csis_inst *cur_inst;
|
||||
static bt_addr_le_t addr_found[CONFIG_BT_MAX_CONN];
|
||||
static const struct bt_csis_client_set_member *locked_members[CONFIG_BT_MAX_CONN];
|
||||
static const struct bt_csip_set_coordinator_set_member *locked_members[CONFIG_BT_MAX_CONN];
|
||||
|
||||
static bool is_discovered(const bt_addr_le_t *addr)
|
||||
{
|
||||
|
@ -76,8 +76,8 @@ static struct bt_conn_cb conn_callbacks = {
|
|||
.disconnected = disconnected_cb
|
||||
};
|
||||
|
||||
static void csis_discover_cb(struct bt_conn *conn,
|
||||
const struct bt_csis_client_set_member *member,
|
||||
static void csip_discover_cb(struct bt_conn *conn,
|
||||
const struct bt_csip_set_coordinator_set_member *member,
|
||||
int err, size_t set_count)
|
||||
{
|
||||
uint8_t conn_index;
|
||||
|
@ -104,7 +104,7 @@ static void csis_discover_cb(struct bt_conn *conn,
|
|||
set_members[conn_index] = member;
|
||||
}
|
||||
|
||||
static void csis_client_lock_set_cb(int err)
|
||||
static void csip_set_coordinator_lock_set_cb(int err)
|
||||
{
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "Lock sets failed (%d)", err);
|
||||
|
@ -114,7 +114,7 @@ static void csis_client_lock_set_cb(int err)
|
|||
shell_print(ctx_shell, "Set locked");
|
||||
}
|
||||
|
||||
static void csis_client_release_set_cb(int err)
|
||||
static void csip_set_coordinator_release_set_cb(int err)
|
||||
{
|
||||
if (err != 0) {
|
||||
shell_error(ctx_shell, "Lock sets failed (%d)", err);
|
||||
|
@ -124,9 +124,9 @@ static void csis_client_release_set_cb(int err)
|
|||
shell_print(ctx_shell, "Set released");
|
||||
}
|
||||
|
||||
static void csis_client_ordered_access_cb(const struct bt_csis_client_set_info *set_info,
|
||||
int err, bool locked,
|
||||
struct bt_csis_client_set_member *member)
|
||||
static void csip_set_coordinator_ordered_access_cb(
|
||||
const struct bt_csip_set_coordinator_set_info *set_info, int err,
|
||||
bool locked, struct bt_csip_set_coordinator_set_member *member)
|
||||
{
|
||||
if (err) {
|
||||
printk("Ordered access failed with err %d\n", err);
|
||||
|
@ -138,16 +138,16 @@ static void csis_client_ordered_access_cb(const struct bt_csis_client_set_info *
|
|||
}
|
||||
}
|
||||
|
||||
static struct bt_csis_client_cb cbs = {
|
||||
.lock_set = csis_client_lock_set_cb,
|
||||
.release_set = csis_client_release_set_cb,
|
||||
.discover = csis_discover_cb,
|
||||
.ordered_access = csis_client_ordered_access_cb
|
||||
static struct bt_csip_set_coordinator_cb cbs = {
|
||||
.lock_set = csip_set_coordinator_lock_set_cb,
|
||||
.release_set = csip_set_coordinator_release_set_cb,
|
||||
.discover = csip_discover_cb,
|
||||
.ordered_access = csip_set_coordinator_ordered_access_cb
|
||||
};
|
||||
|
||||
static bool csis_client_oap_cb(const struct bt_csis_client_set_info *set_info,
|
||||
struct bt_csis_client_set_member *members[],
|
||||
size_t count)
|
||||
static bool csip_set_coordinator_oap_cb(const struct bt_csip_set_coordinator_set_info *set_info,
|
||||
struct bt_csip_set_coordinator_set_member *members[],
|
||||
size_t count)
|
||||
{
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
printk("Ordered access for members[%zu]: %p\n", i, members[i]);
|
||||
|
@ -156,14 +156,14 @@ static bool csis_client_oap_cb(const struct bt_csis_client_set_info *set_info,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool csis_found(struct bt_data *data, void *user_data)
|
||||
static bool csip_found(struct bt_data *data, void *user_data)
|
||||
{
|
||||
if (bt_csis_client_is_set_member(cur_inst->info.set_sirk, data)) {
|
||||
if (bt_csip_set_coordinator_is_set_member(cur_inst->info.set_sirk, data)) {
|
||||
bt_addr_le_t *addr = user_data;
|
||||
char addr_str[BT_ADDR_LE_STR_LEN];
|
||||
|
||||
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
|
||||
shell_print(ctx_shell, "Found CSIS advertiser with address %s",
|
||||
shell_print(ctx_shell, "Found CSIP advertiser with address %s",
|
||||
addr_str);
|
||||
|
||||
if (is_discovered(addr)) {
|
||||
|
@ -197,19 +197,19 @@ static bool csis_found(struct bt_data *data, void *user_data)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void csis_client_scan_recv(const struct bt_le_scan_recv_info *info,
|
||||
struct net_buf_simple *ad)
|
||||
static void csip_set_coordinator_scan_recv(const struct bt_le_scan_recv_info *info,
|
||||
struct net_buf_simple *ad)
|
||||
{
|
||||
/* We're only interested in connectable events */
|
||||
if (info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) {
|
||||
if (cur_inst != NULL) {
|
||||
bt_data_parse(ad, csis_found, (void *)info->addr);
|
||||
bt_data_parse(ad, csip_found, (void *)info->addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct bt_le_scan_cb csis_client_scan_callbacks = {
|
||||
.recv = csis_client_scan_recv
|
||||
static struct bt_le_scan_cb csip_set_coordinator_scan_callbacks = {
|
||||
.recv = csip_set_coordinator_scan_recv
|
||||
};
|
||||
|
||||
static void discover_members_timer_handler(struct k_work *work)
|
||||
|
@ -225,8 +225,8 @@ static void discover_members_timer_handler(struct k_work *work)
|
|||
}
|
||||
}
|
||||
|
||||
static int cmd_csis_client_init(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
static int cmd_csip_set_coordinator_init(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
{
|
||||
static bool initialized;
|
||||
|
||||
|
@ -236,8 +236,8 @@ static int cmd_csis_client_init(const struct shell *sh, size_t argc,
|
|||
|
||||
k_work_init_delayable(&discover_members_timer,
|
||||
discover_members_timer_handler);
|
||||
bt_le_scan_cb_register(&csis_client_scan_callbacks);
|
||||
bt_csis_client_register_cb(&cbs);
|
||||
bt_le_scan_cb_register(&csip_set_coordinator_scan_callbacks);
|
||||
bt_csip_set_coordinator_register_cb(&cbs);
|
||||
bt_conn_cb_register(&conn_callbacks);
|
||||
|
||||
initialized = true;
|
||||
|
@ -245,8 +245,8 @@ static int cmd_csis_client_init(const struct shell *sh, size_t argc,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_csis_client_discover(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
static int cmd_csip_set_coordinator_discover(const struct shell *sh,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
char addr[BT_ADDR_LE_STR_LEN];
|
||||
long member_index = 0;
|
||||
|
@ -270,9 +270,10 @@ static int cmd_csis_client_discover(const struct shell *sh, size_t argc,
|
|||
conn = conns[member_index];
|
||||
|
||||
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
||||
|
||||
shell_print(sh, "Discovering for member[%u] (%s)",
|
||||
(uint8_t)member_index, addr);
|
||||
err = bt_csis_client_discover(conn);
|
||||
err = bt_csip_set_coordinator_discover(conn);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Fail: %d", err);
|
||||
}
|
||||
|
@ -280,12 +281,12 @@ static int cmd_csis_client_discover(const struct shell *sh, size_t argc,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int cmd_csis_client_discover_members(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
static int cmd_csip_set_coordinator_discover_members(const struct shell *sh,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
cur_inst = (struct bt_csis_client_csis_inst *)strtol(argv[1], NULL, 0);
|
||||
cur_inst = (struct bt_csip_set_coordinator_csis_inst *)strtol(argv[1], NULL, 0);
|
||||
|
||||
if (cur_inst == NULL) {
|
||||
shell_error(sh, "NULL set");
|
||||
|
@ -308,7 +309,7 @@ static int cmd_csis_client_discover_members(const struct shell *sh, size_t argc,
|
|||
}
|
||||
|
||||
err = k_work_reschedule(&discover_members_timer,
|
||||
CSIS_CLIENT_DISCOVER_TIMER_VALUE);
|
||||
BT_CSIP_SET_COORDINATOR_DISCOVER_TIMER_VALUE);
|
||||
if (err < 0) { /* Can return 0, 1 and 2 for success */
|
||||
shell_error(sh,
|
||||
"Could not schedule discover_members_timer %d",
|
||||
|
@ -324,8 +325,8 @@ static int cmd_csis_client_discover_members(const struct shell *sh, size_t argc,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int cmd_csis_client_lock_set(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
static int cmd_csip_set_coordinator_lock_set(const struct shell *sh,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
int conn_count = 0;
|
||||
|
@ -341,7 +342,8 @@ static int cmd_csis_client_lock_set(const struct shell *sh, size_t argc,
|
|||
}
|
||||
}
|
||||
|
||||
err = bt_csis_client_lock(locked_members, conn_count, &cur_inst->info);
|
||||
err = bt_csip_set_coordinator_lock(locked_members, conn_count,
|
||||
&cur_inst->info);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Fail: %d", err);
|
||||
}
|
||||
|
@ -349,8 +351,8 @@ static int cmd_csis_client_lock_set(const struct shell *sh, size_t argc,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int cmd_csis_client_release_set(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
static int cmd_csip_set_coordinator_release_set(const struct shell *sh,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
int conn_count = 0;
|
||||
|
@ -366,7 +368,8 @@ static int cmd_csis_client_release_set(const struct shell *sh, size_t argc,
|
|||
}
|
||||
}
|
||||
|
||||
err = bt_csis_client_release(locked_members, conn_count, &cur_inst->info);
|
||||
err = bt_csip_set_coordinator_release(locked_members, conn_count,
|
||||
&cur_inst->info);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Fail: %d", err);
|
||||
}
|
||||
|
@ -374,12 +377,12 @@ static int cmd_csis_client_release_set(const struct shell *sh, size_t argc,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int cmd_csis_client_ordered_access(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
static int cmd_csip_set_coordinator_ordered_access(const struct shell *sh,
|
||||
size_t argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
long member_count = (long)ARRAY_SIZE(set_members);
|
||||
const struct bt_csis_client_set_member *members[ARRAY_SIZE(set_members)];
|
||||
const struct bt_csip_set_coordinator_set_member *members[ARRAY_SIZE(set_members)];
|
||||
|
||||
if (argc > 1) {
|
||||
member_count = strtol(argv[1], NULL, 0);
|
||||
|
@ -395,9 +398,10 @@ static int cmd_csis_client_ordered_access(const struct shell *sh, size_t argc,
|
|||
members[i] = set_members[i];
|
||||
}
|
||||
|
||||
err = bt_csis_client_ordered_access(members, ARRAY_SIZE(members),
|
||||
&cur_inst->info,
|
||||
csis_client_oap_cb);
|
||||
err = bt_csip_set_coordinator_ordered_access(members,
|
||||
ARRAY_SIZE(members),
|
||||
&cur_inst->info,
|
||||
csip_set_coordinator_oap_cb);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Fail: %d", err);
|
||||
}
|
||||
|
@ -405,12 +409,12 @@ static int cmd_csis_client_ordered_access(const struct shell *sh, size_t argc,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int cmd_csis_client_lock(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
static int cmd_csip_set_coordinator_lock(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
{
|
||||
int err;
|
||||
long member_index = 0;
|
||||
const struct bt_csis_client_set_member *lock_member[1];
|
||||
const struct bt_csip_set_coordinator_set_member *lock_member[1];
|
||||
|
||||
if (cur_inst == NULL) {
|
||||
shell_error(sh, "No set selected");
|
||||
|
@ -430,7 +434,7 @@ static int cmd_csis_client_lock(const struct shell *sh, size_t argc,
|
|||
|
||||
lock_member[0] = set_members[member_index];
|
||||
|
||||
err = bt_csis_client_lock(lock_member, 1, &cur_inst->info);
|
||||
err = bt_csip_set_coordinator_lock(lock_member, 1, &cur_inst->info);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Fail: %d", err);
|
||||
}
|
||||
|
@ -438,12 +442,12 @@ static int cmd_csis_client_lock(const struct shell *sh, size_t argc,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int cmd_csis_client_release(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
static int cmd_csip_set_coordinator_release(const struct shell *sh, size_t argc,
|
||||
char *argv[])
|
||||
{
|
||||
int err;
|
||||
long member_index = 0;
|
||||
const struct bt_csis_client_set_member *lock_member[1];
|
||||
const struct bt_csip_set_coordinator_set_member *lock_member[1];
|
||||
|
||||
if (cur_inst == NULL) {
|
||||
shell_error(sh, "No set selected");
|
||||
|
@ -463,7 +467,7 @@ static int cmd_csis_client_release(const struct shell *sh, size_t argc,
|
|||
|
||||
lock_member[0] = set_members[member_index];
|
||||
|
||||
err = bt_csis_client_release(lock_member, 1, &cur_inst->info);
|
||||
err = bt_csip_set_coordinator_release(lock_member, 1, &cur_inst->info);
|
||||
if (err != 0) {
|
||||
shell_error(sh, "Fail: %d", err);
|
||||
}
|
||||
|
@ -471,7 +475,8 @@ static int cmd_csis_client_release(const struct shell *sh, size_t argc,
|
|||
return err;
|
||||
}
|
||||
|
||||
static int cmd_csis_client(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_csip_set_coordinator(const struct shell *sh, size_t argc,
|
||||
char **argv)
|
||||
{
|
||||
if (argc > 1) {
|
||||
shell_error(sh, "%s unknown parameter: %s",
|
||||
|
@ -483,34 +488,34 @@ static int cmd_csis_client(const struct shell *sh, size_t argc, char **argv)
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(csis_client_cmds,
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(csip_set_coordinator_cmds,
|
||||
SHELL_CMD_ARG(init, NULL,
|
||||
"Initialize CSIS_CLIENT",
|
||||
cmd_csis_client_init, 1, 1),
|
||||
"Initialize csip_set_coordinator",
|
||||
cmd_csip_set_coordinator_init, 1, 1),
|
||||
SHELL_CMD_ARG(discover, NULL,
|
||||
"Run discover for CSIS on peer device [member_index]",
|
||||
cmd_csis_client_discover, 1, 1),
|
||||
cmd_csip_set_coordinator_discover, 1, 1),
|
||||
SHELL_CMD_ARG(discover_members, NULL,
|
||||
"Scan for set members <set_pointer>",
|
||||
cmd_csis_client_discover_members, 2, 0),
|
||||
cmd_csip_set_coordinator_discover_members, 2, 0),
|
||||
SHELL_CMD_ARG(lock_set, NULL,
|
||||
"Lock set",
|
||||
cmd_csis_client_lock_set, 1, 0),
|
||||
cmd_csip_set_coordinator_lock_set, 1, 0),
|
||||
SHELL_CMD_ARG(release_set, NULL,
|
||||
"Release set",
|
||||
cmd_csis_client_release_set, 1, 0),
|
||||
cmd_csip_set_coordinator_release_set, 1, 0),
|
||||
SHELL_CMD_ARG(lock, NULL,
|
||||
"Lock specific member [member_index]",
|
||||
cmd_csis_client_lock, 1, 1),
|
||||
cmd_csip_set_coordinator_lock, 1, 1),
|
||||
SHELL_CMD_ARG(release, NULL,
|
||||
"Release specific member [member_index]",
|
||||
cmd_csis_client_release, 1, 1),
|
||||
cmd_csip_set_coordinator_release, 1, 1),
|
||||
SHELL_CMD_ARG(ordered_access, NULL,
|
||||
"Perform dummy ordered access procedure [member_count]",
|
||||
cmd_csis_client_ordered_access, 1, 1),
|
||||
cmd_csip_set_coordinator_ordered_access, 1, 1),
|
||||
SHELL_SUBCMD_SET_END
|
||||
);
|
||||
|
||||
SHELL_CMD_ARG_REGISTER(csis_client, &csis_client_cmds,
|
||||
"Bluetooth CSIS_CLIENT shell commands",
|
||||
cmd_csis_client, 1, 1);
|
||||
SHELL_CMD_ARG_REGISTER(csip_set_coordinator, &csip_set_coordinator_cmds,
|
||||
"Bluetooth csip_set_coordinator shell commands",
|
||||
cmd_csip_set_coordinator, 1, 1);
|
Loading…
Add table
Add a link
Reference in a new issue