From e748e76988d4ccab73d32b6a2dfdbf5426193e3a Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Tue, 26 Oct 2021 16:36:33 +0200 Subject: [PATCH] Bluetooth: Audio: Move csis.h to include/bluetooth/audio Move the header file csis.h from the internal location to the public include directory. This file is supposed to provide the public API for CSIS and the CSIS client, but is not fully complete yet. Signed-off-by: Emil Gydesen --- .../bluetooth/audio/csis.h | 203 +++++++++++++++++- subsys/bluetooth/audio/csis.h | 183 ---------------- subsys/bluetooth/audio/csis_client.c | 2 +- subsys/bluetooth/audio/csis_crypto.h | 2 +- subsys/bluetooth/audio/csis_internal.h | 7 +- subsys/bluetooth/shell/csis.c | 2 +- subsys/bluetooth/shell/csis_client.c | 2 +- .../bsim_test_audio/src/csis_client_test.c | 2 +- .../bsim_bt/bsim_test_audio/src/csis_test.c | 2 +- 9 files changed, 202 insertions(+), 203 deletions(-) rename subsys/bluetooth/audio/csis_client.h => include/bluetooth/audio/csis.h (53%) delete mode 100644 subsys/bluetooth/audio/csis.h diff --git a/subsys/bluetooth/audio/csis_client.h b/include/bluetooth/audio/csis.h similarity index 53% rename from subsys/bluetooth/audio/csis_client.h rename to include/bluetooth/audio/csis.h index 93282a5dbe7..7bac1791fef 100644 --- a/subsys/bluetooth/audio/csis_client.h +++ b/include/bluetooth/audio/csis.h @@ -1,17 +1,31 @@ -/** @file - * @brief APIs for Bluetooth Coordinated Set Identification Client - * - * Copyright (c) 2020 Bose Corporation +/** * Copyright (c) 2021 Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ -#include +#ifndef ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_CSIS_H_ +#define ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_CSIS_H_ + +/** + * @brief Coordinated Set Identification Service (CSIS) + * + * @defgroup bt_gatt_csis Coordinated Set Identification Service (CSIS) + * + * @ingroup bluetooth + * @{ + * * + * [Experimental] Users should note that the APIs can change as a part of ongoing development. + */ + + +#include +#include #include -#include -#include "csis.h" -#include "csis_internal.h" + +#ifdef __cplusplus +extern "C" { +#endif /* Recommended timer for member discovery */ #define CSIS_CLIENT_DISCOVER_TIMER_VALUE K_SECONDS(10) @@ -22,6 +36,168 @@ #define BT_CSIS_CLIENT_MAX_CSIS_INSTANCES 0 #endif /* CONFIG_BT_CSIS_CLIENT */ +#define BT_CSIS_MINIMUM_SET_SIZE 2 +#define BT_CSIS_PSRI_SIZE 6 + +/** Accept the request to read the SIRK as plaintext */ +#define BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT 0x00 +/** Accept the request to read the SIRK, but return encrypted SIRK */ +#define BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT_ENC 0x01 +/** Reject the request to read the SIRK */ +#define BT_CSIS_READ_SIRK_REQ_RSP_REJECT 0x02 +/** SIRK is available only via an OOB procedure */ +#define BT_CSIS_READ_SIRK_REQ_RSP_OOB_ONLY 0x03 + +#define BT_CSIS_SET_SIRK_SIZE 16 + +#define BT_CSIS_ERROR_LOCK_DENIED 0x80 +#define BT_CSIS_ERROR_LOCK_RELEASE_DENIED 0x81 +#define BT_CSIS_ERROR_LOCK_INVAL_VALUE 0x82 +#define BT_CSIS_ERROR_SIRK_ACCESS_REJECTED 0x83 +#define BT_CSIS_ERROR_SIRK_OOB_ONLY 0x84 +#define BT_CSIS_ERROR_LOCK_ALREADY_GRANTED 0x85 + +#define BT_CSIS_RELEASE_VALUE 0x01 +#define BT_CSIS_LOCK_VALUE 0x02 + +#define BT_CSIS_SIRK_TYPE_ENCRYPTED 0x00 +#define BT_CSIS_SIRK_TYPE_PLAIN 0x01 + +/** @brief Opaque Coordinated Set Identification Service instance. */ +struct bt_csis; + +struct bt_csis_cb { + /** + * @brief Callback whenever the lock changes on the server. + * + * @param conn The connection to the client that changed the lock. + * NULL if server changed it, either by calling + * bt_csis_lock() or by timeout. + * @param csis Pointer to the Coordinated Set Identification Service. + * @param locked Whether the lock was locked or released. + * + */ + void (*lock_changed)(struct bt_conn *conn, struct bt_csis *csis, + bool locked); + + /** + * @brief Request from a peer device to read the sirk. + * + * If this callback is not set, all clients will be allowed to read + * the SIRK unencrypted. + * + * @param conn The connection to the client that requested to read the + * SIRK. + * @param csis Pointer to the Coordinated Set Identification Service. + * + * @return A BT_CSIS_READ_SIRK_REQ_RSP_* response code. + */ + uint8_t (*sirk_read_req)(struct bt_conn *conn, struct bt_csis *csis); +}; + +/** Register structure for Coordinated Set Identification Service */ +struct bt_csis_register_param { + /** + * @brief Size of the set. + * + * If set to 0, the set size characteric won't be initialized. + * Otherwise shall be set to minimum 2. + */ + uint8_t set_size; + + /** + * @brief The unique Set Identity Resolving Key (SIRK) + * + * This shall be unique between different sets, and shall be the same + * for each set member for each set. + */ + uint8_t set_sirk[BT_CSIS_SET_SIRK_SIZE]; + + /** + * @brief Boolean to set whether the set is lockable by clients + * + * Setting this to false will disable the lock characteristic. + */ + bool lockable; + + /** + * @brief Rank of this device in this set. + * + * If the lockable parameter is set to true, this shall be > 0 and + * <= to the set_size. If the lockable parameter is set to false, this + * may be set to 0 to disable the rank characteristic. + */ + uint8_t rank; + + /** Pointer to the callback structure. */ + struct bt_csis_cb *cb; +}; + +/** + * @brief Get the service declaration attribute. + * + * The first service attribute can be included in any other GATT service. + * + * @param csis Pointer to the Coordinated Set Identification Service. + * + * @return The first CSIS attribute instance. + */ +void *bt_csis_svc_decl_get(const struct bt_csis *csis); + +/** + * @brief Register the Coordinated Set Identification Service. + * + * This will register and enable the service and make it discoverable by + * clients. + * + * This shall only be done as a server. + * + * @param param Coordinated Set Identification Service register parameters. + * @param[out] csis Pointer to the registered Coordinated Set Identification + * Service. + * + * @return 0 if success, errno on failure. + */ +int bt_csis_register(const struct bt_csis_register_param *param, + struct bt_csis **csis); + +/** + * @brief Print the sirk to the debug output + * + * @param csis Pointer to the Coordinated Set Identification Service. + */ +void bt_csis_print_sirk(const struct bt_csis *csis); + +/** + * @brief Starts advertising the PRSI value. + * + * This cannot be used with other connectable advertising sets. + * + * @param csis Pointer to the Coordinated Set Identification Service. + * @param enable If true start advertising, if false stop advertising + * + * @return int 0 if on success, ERRNO on error. + */ +int bt_csis_advertise(struct bt_csis *csis, bool enable); + +/** + * @brief Locks the sets on the server. + * + * @param csis Pointer to the Coordinated Set Identification Service. + * @param lock If true lock the set, if false release the set. + * @param force This argument only have meaning when @p lock is false + * (release) and will force release the lock, regardless of who + * took the lock. + * + * @return 0 on success, GATT error on error. + */ +int bt_csis_lock(struct bt_csis *csis, bool lock, bool force); + +struct bt_csis_set_sirk { + uint8_t type; + uint8_t value[BT_CSIS_SET_SIRK_SIZE]; +} __packed; + struct bt_csis_client_set { struct bt_csis_set_sirk set_sirk; uint8_t set_size; @@ -210,3 +386,14 @@ int bt_csis_client_lock(const struct bt_csis_client_set_member **members, */ int bt_csis_client_release(const struct bt_csis_client_set_member **members, uint8_t count, const struct bt_csis_client_set *set); + + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_CSIS_H_ */ diff --git a/subsys/bluetooth/audio/csis.h b/subsys/bluetooth/audio/csis.h deleted file mode 100644 index 44f22c8e1ba..00000000000 --- a/subsys/bluetooth/audio/csis.h +++ /dev/null @@ -1,183 +0,0 @@ -/** - * @file - * @brief APIs for Bluetooth CSIS - * - * Copyright (c) 2019 Bose Corporation - * Copyright (c) 2020-2021 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_CSIS_H_ -#define ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_CSIS_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define BT_CSIS_MINIMUM_SET_SIZE 2 -#define BT_CSIS_PSRI_SIZE 6 - -/** Accept the request to read the SIRK as plaintext */ -#define BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT 0x00 -/** Accept the request to read the SIRK, but return encrypted SIRK */ -#define BT_CSIS_READ_SIRK_REQ_RSP_ACCEPT_ENC 0x01 -/** Reject the request to read the SIRK */ -#define BT_CSIS_READ_SIRK_REQ_RSP_REJECT 0x02 -/** SIRK is available only via an OOB procedure */ -#define BT_CSIS_READ_SIRK_REQ_RSP_OOB_ONLY 0x03 - -#define BT_CSIS_SET_SIRK_SIZE 16 - -#define BT_CSIS_ERROR_LOCK_DENIED 0x80 -#define BT_CSIS_ERROR_LOCK_RELEASE_DENIED 0x81 -#define BT_CSIS_ERROR_LOCK_INVAL_VALUE 0x82 -#define BT_CSIS_ERROR_SIRK_ACCESS_REJECTED 0x83 -#define BT_CSIS_ERROR_SIRK_OOB_ONLY 0x84 -#define BT_CSIS_ERROR_LOCK_ALREADY_GRANTED 0x85 - -#define BT_CSIS_RELEASE_VALUE 0x01 -#define BT_CSIS_LOCK_VALUE 0x02 - -#define BT_CSIS_SIRK_TYPE_ENCRYPTED 0x00 -#define BT_CSIS_SIRK_TYPE_PLAIN 0x01 - -/** @brief Opaque Coordinated Set Identification Service instance. */ -struct bt_csis; - -struct bt_csis_cb { - /** - * @brief Callback whenever the lock changes on the server. - * - * @param conn The connection to the client that changed the lock. - * NULL if server changed it, either by calling - * @ref csis_lock or by timeout. - * @param csis Pointer to the Coordinated Set Identification Service. - * @param locked Whether the lock was locked or released. - * - */ - void (*lock_changed)(struct bt_conn *conn, struct bt_csis *csis, - bool locked); - - /** - * @brief Request from a peer device to read the sirk. - * - * If this callback is not set, all clients will be allowed to read - * the SIRK unencrypted. - * - * @param conn The connection to the client that requested to read the - * SIRK. - * @param csis Pointer to the Coordinated Set Identification Service. - * - * @return A BT_CSIS_READ_SIRK_REQ_RSP_* response code. - */ - uint8_t (*sirk_read_req)(struct bt_conn *conn, struct bt_csis *csis); -}; - -/** Register structure for Coordinated Set Identification Service */ -struct bt_csis_register_param { - /** - * @brief Size of the set. - * - * If set to 0, the set size characteric won't be initialized. - * Otherwise shall be set to minimum 2. - */ - uint8_t set_size; - - /** - * @brief The unique Set Identity Resolving Key (SIRK) - * - * This shall be unique between different sets, and shall be the same - * for each set member for each set. - */ - uint8_t set_sirk[BT_CSIS_SET_SIRK_SIZE]; - - /** - * @brief Boolean to set whether the set is lockable by clients - * - * Setting this to false will disable the lock characteristic. - */ - bool lockable; - - /** - * @brief Rank of this device in this set. - * - * If the lockable parameter is set to true, this shall be > 0 and - * <= to the set_size. If the lockable parameter is set to false, this - * may be set to 0 to disable the rank characteristic. - */ - uint8_t rank; - - /** Pointer to the callback structure. */ - struct bt_csis_cb *cb; -}; - -/** - * @brief Get the service declaration attribute. - * - * The first service attribute can be included in any other GATT service. - * - * @param csis Pointer to the Coordinated Set Identification Service. - * - * @return The first CSIS attribute instance. - */ -void *bt_csis_svc_decl_get(const struct bt_csis *csis); - -/** - * @brief Register the Coordinated Set Identification Service. - * - * This will register and enable the service and make it discoverable by - * clients. - * - * This shall only be done as a server. - * - * @param param Coordinated Set Identification Service register parameters. - * @param[out] csis Pointer to the registered Coordinated Set Identification - * Service. - * - * @return 0 if success, errno on failure. - */ -int bt_csis_register(const struct bt_csis_register_param *param, - struct bt_csis **csis); - -/** - * @brief Print the sirk to the debug output - * - * @param csis Pointer to the Coordinated Set Identification Service. - */ -void bt_csis_print_sirk(const struct bt_csis *csis); - -/** - * @brief Starts advertising the PRSI value. - * - * This cannot be used with other connectable advertising sets. - * - * @param csis Pointer to the Coordinated Set Identification Service. - * @param enable If true start advertising, if false stop advertising - * - * @return int 0 if on success, ERRNO on error. - */ -int bt_csis_advertise(struct bt_csis *csis, bool enable); - -/** - * @brief Locks the sets on the server. - * - * @param csis Pointer to the Coordinated Set Identification Service. - * @param lock If true lock the set, if false release the set. - * @param force This argument only have meaning when @p lock is false - * (release) and will force release the lock, regardless of who - * took the lock. - * - * @return 0 on success, GATT error on error. - */ -int bt_csis_lock(struct bt_csis *csis, bool lock, bool force); - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_SUBSYS_BLUETOOTH_AUDIO_CSIS_H_ */ diff --git a/subsys/bluetooth/audio/csis_client.c b/subsys/bluetooth/audio/csis_client.c index bca43c8ce60..05a2af203a8 100644 --- a/subsys/bluetooth/audio/csis_client.c +++ b/subsys/bluetooth/audio/csis_client.c @@ -30,7 +30,7 @@ #include #include #include -#include "csis_client.h" +#include #include "csis_crypto.h" #include "../host/conn_internal.h" #include "../host/keys.h" diff --git a/subsys/bluetooth/audio/csis_crypto.h b/subsys/bluetooth/audio/csis_crypto.h index 2c5d52ec583..6cfb95b5dcb 100644 --- a/subsys/bluetooth/audio/csis_crypto.h +++ b/subsys/bluetooth/audio/csis_crypto.h @@ -8,7 +8,7 @@ #include #include -#include "csis.h" +#include #define BT_CSIS_CRYPTO_KEY_SIZE 16 #define BT_CSIS_CRYPTO_SALT_SIZE 16 diff --git a/subsys/bluetooth/audio/csis_internal.h b/subsys/bluetooth/audio/csis_internal.h index 8cea9d63f4c..843e8e0e41f 100644 --- a/subsys/bluetooth/audio/csis_internal.h +++ b/subsys/bluetooth/audio/csis_internal.h @@ -7,12 +7,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "csis.h" - -struct bt_csis_set_sirk { - uint8_t type; - uint8_t value[BT_CSIS_SET_SIRK_SIZE]; -} __packed; +#include struct csis_pending_notifications { bt_addr_le_t addr; diff --git a/subsys/bluetooth/shell/csis.c b/subsys/bluetooth/shell/csis.c index 11a628f1728..e21b7318047 100644 --- a/subsys/bluetooth/shell/csis.c +++ b/subsys/bluetooth/shell/csis.c @@ -16,7 +16,7 @@ #include #include #include -#include "../audio/csis.h" +#include #include "bt.h" extern const struct shell *ctx_shell; diff --git a/subsys/bluetooth/shell/csis_client.c b/subsys/bluetooth/shell/csis_client.c index d1666c25f32..4331d98adee 100644 --- a/subsys/bluetooth/shell/csis_client.c +++ b/subsys/bluetooth/shell/csis_client.c @@ -20,7 +20,7 @@ #include "bt.h" -#include "../audio/csis_client.h" +#include static uint8_t members_found; static struct k_work_delayable discover_members_timer; diff --git a/tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_client_test.c b/tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_client_test.c index 89d1fab96f9..b3602f2963a 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_client_test.c +++ b/tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_client_test.c @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #ifdef CONFIG_BT_CSIS_CLIENT -#include "../../../../../subsys/bluetooth/audio/csis_client.h" +#include #include "common.h" extern enum bst_result_t bst_result; diff --git a/tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_test.c b/tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_test.c index cc2d8bf586c..9bf89205f22 100644 --- a/tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_test.c +++ b/tests/bluetooth/bsim_bt/bsim_test_audio/src/csis_test.c @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #ifdef CONFIG_BT_CSIS -#include "../../../../../subsys/bluetooth/audio/csis.h" +#include #include "common.h"