Bluetooth: GATT: Add support to setting permission on CCCD

This adds support to set different permissions to CCCD so security can
be checked when enabling notification which conforms to:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2360:

  '3.3.3.3 Client Characteristic Configuration

   Authentication and authorization may be required by the server to
   write the configuration descriptor.'

In addition to that also ensure that notification are not re-enabled
until the proper security level is reached to conform to the following
statement:

  '10.3.1.1 Handling of GATT indications and notifications

   A client “requests” a server to send indications and notifications
   by appropriately configuring the server via a Client Characteristic
   Configuration Descriptor. Since the configuration is persistent
   across a disconnection and reconnection, security requirements must
   be checked against the configuration upon a reconnection before
   sending indications or notifications. When a server reconnects to a
   client to send an indication or notification for which security is
   required, the server shall initiate or request encryption with the
   client prior to sending an indication or notification. If the client
   does not have an LTK indicating that the client has lost the bond,
   enabling encryption will fail.'

Fixes #17983

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2019-09-04 14:15:07 +03:00 committed by Johan Hedberg
commit 03b9ce487c
18 changed files with 115 additions and 28 deletions

View file

@ -641,10 +641,10 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
* Helper macro to declare a Managed CCC attribute.
*
* @param _ccc CCC attribute user data, shall point to a _bt_gatt_ccc.
* @param _perm CCC access permissions.
*/
#define BT_GATT_CCC_MANAGED(_ccc) \
BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, \
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, \
#define BT_GATT_CCC_MANAGED(_ccc, _perm) \
BT_GATT_ATTRIBUTE(BT_UUID_GATT_CCC, _perm, \
bt_gatt_attr_read_ccc, bt_gatt_attr_write_ccc, \
_ccc)
@ -653,11 +653,12 @@ ssize_t bt_gatt_attr_write_ccc(struct bt_conn *conn,
*
* Helper macro to declare a CCC attribute.
*
* @param _cfg_changed Configuration changed callback.
* @param _changed Configuration changed callback.
* @param _perm CCC access permissions.
*/
#define BT_GATT_CCC(_cfg_changed) \
BT_GATT_CCC_MANAGED((&(struct _bt_gatt_ccc) \
BT_GATT_CCC_INITIALIZER(_cfg_changed, NULL, NULL)))
#define BT_GATT_CCC(_changed, _perm) \
BT_GATT_CCC_MANAGED((&(struct _bt_gatt_ccc) \
BT_GATT_CCC_INITIALIZER(_changed, NULL, NULL)), _perm)
/** @brief Read Characteristic Extended Properties Attribute helper
*