Bluetooth: GATT: Fix const'ness of characteristic descriptor data

None of the data for the CEP, CUD and CPF descriptors needs to be
modified by the stack at runtime. Make it possible to pass constant
data to the descriptor macros, and make sure the descriptor handlers
cast the data back to be a constant.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2018-09-18 08:47:15 +03:00 committed by Johan Hedberg
commit 366378f8ac
2 changed files with 6 additions and 6 deletions

View file

@ -582,7 +582,7 @@ ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn,
*/ */
#define BT_GATT_CEP(_value) \ #define BT_GATT_CEP(_value) \
BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \ BT_GATT_DESCRIPTOR(BT_UUID_GATT_CEP, BT_GATT_PERM_READ, \
bt_gatt_attr_read_cep, NULL, _value) bt_gatt_attr_read_cep, NULL, (void *)_value)
/** @brief Read Characteristic User Description Descriptor Attribute helper /** @brief Read Characteristic User Description Descriptor Attribute helper
* *
@ -613,7 +613,7 @@ ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
*/ */
#define BT_GATT_CUD(_value, _perm) \ #define BT_GATT_CUD(_value, _perm) \
BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \ BT_GATT_DESCRIPTOR(BT_UUID_GATT_CUD, _perm, bt_gatt_attr_read_cud, \
NULL, _value) NULL, (void *)_value)
/** @brief Read Characteristic Presentation format Descriptor Attribute helper /** @brief Read Characteristic Presentation format Descriptor Attribute helper
* *
@ -643,7 +643,7 @@ ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
*/ */
#define BT_GATT_CPF(_value) \ #define BT_GATT_CPF(_value) \
BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \ BT_GATT_DESCRIPTOR(BT_UUID_GATT_CPF, BT_GATT_PERM_READ, \
bt_gatt_attr_read_cpf, NULL, (void * const)_value) bt_gatt_attr_read_cpf, NULL, (void *)_value)
/** @def BT_GATT_DESCRIPTOR /** @def BT_GATT_DESCRIPTOR
* @brief Descriptor Declaration Macro. * @brief Descriptor Declaration Macro.

View file

@ -651,7 +651,7 @@ ssize_t bt_gatt_attr_read_cep(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf, const struct bt_gatt_attr *attr, void *buf,
u16_t len, u16_t offset) u16_t len, u16_t offset)
{ {
struct bt_gatt_cep *value = attr->user_data; const struct bt_gatt_cep *value = attr->user_data;
u16_t props = sys_cpu_to_le16(value->properties); u16_t props = sys_cpu_to_le16(value->properties);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &props, return bt_gatt_attr_read(conn, attr, buf, len, offset, &props,
@ -662,7 +662,7 @@ ssize_t bt_gatt_attr_read_cud(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf, const struct bt_gatt_attr *attr, void *buf,
u16_t len, u16_t offset) u16_t len, u16_t offset)
{ {
char *value = attr->user_data; const char *value = attr->user_data;
return bt_gatt_attr_read(conn, attr, buf, len, offset, value, return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
strlen(value)); strlen(value));
@ -672,7 +672,7 @@ ssize_t bt_gatt_attr_read_cpf(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf, const struct bt_gatt_attr *attr, void *buf,
u16_t len, u16_t offset) u16_t len, u16_t offset)
{ {
struct bt_gatt_cpf *value = attr->user_data; const struct bt_gatt_cpf *value = attr->user_data;
return bt_gatt_attr_read(conn, attr, buf, len, offset, value, return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
sizeof(*value)); sizeof(*value));