Bluetooth: ATT: Merge all permission check in one place
This merges callback checks with permissions checks so there are done in one place. Change-Id: Ic51b2be9cda67eac9e5dc1ebcbf6186ad5007bf4 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
b7702334c4
commit
c116fc42e0
1 changed files with 2 additions and 19 deletions
|
@ -542,12 +542,12 @@ static uint8_t check_perm(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
||||||
uint8_t mask)
|
uint8_t mask)
|
||||||
{
|
{
|
||||||
if ((mask & BT_GATT_PERM_READ) &&
|
if ((mask & BT_GATT_PERM_READ) &&
|
||||||
!(attr->perm & BT_GATT_PERM_READ_MASK)) {
|
(!(attr->perm & BT_GATT_PERM_READ_MASK) || !attr->read)) {
|
||||||
return BT_ATT_ERR_READ_NOT_PERMITTED;
|
return BT_ATT_ERR_READ_NOT_PERMITTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mask & BT_GATT_PERM_WRITE) &&
|
if ((mask & BT_GATT_PERM_WRITE) &&
|
||||||
!(attr->perm & BT_GATT_PERM_WRITE_MASK)) {
|
(!(attr->perm & BT_GATT_PERM_WRITE_MASK) || !attr->write)) {
|
||||||
return BT_ATT_ERR_WRITE_NOT_PERMITTED;
|
return BT_ATT_ERR_WRITE_NOT_PERMITTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,11 +761,6 @@ static uint8_t read_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||||
*/
|
*/
|
||||||
data->err = 0x00;
|
data->err = 0x00;
|
||||||
|
|
||||||
if (!attr->read) {
|
|
||||||
data->err = BT_ATT_ERR_READ_NOT_PERMITTED;
|
|
||||||
return BT_GATT_ITER_STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check attribute permissions */
|
/* Check attribute permissions */
|
||||||
data->err = check_perm(conn, attr, BT_GATT_PERM_READ_MASK);
|
data->err = check_perm(conn, attr, BT_GATT_PERM_READ_MASK);
|
||||||
if (data->err) {
|
if (data->err) {
|
||||||
|
@ -1072,12 +1067,6 @@ static uint8_t write_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||||
|
|
||||||
BT_DBG("handle 0x%04x offset %u", attr->handle, data->offset);
|
BT_DBG("handle 0x%04x offset %u", attr->handle, data->offset);
|
||||||
|
|
||||||
/* Check for write support */
|
|
||||||
if (!attr->write) {
|
|
||||||
data->err = BT_ATT_ERR_WRITE_NOT_PERMITTED;
|
|
||||||
return BT_GATT_ITER_STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check attribute permissions */
|
/* Check attribute permissions */
|
||||||
data->err = check_perm(data->conn, attr, BT_GATT_PERM_WRITE_MASK);
|
data->err = check_perm(data->conn, attr, BT_GATT_PERM_WRITE_MASK);
|
||||||
if (data->err) {
|
if (data->err) {
|
||||||
|
@ -1177,12 +1166,6 @@ static uint8_t prep_write_cb(const struct bt_gatt_attr *attr, void *user_data)
|
||||||
|
|
||||||
BT_DBG("handle 0x%04x offset %u", attr->handle, data->offset);
|
BT_DBG("handle 0x%04x offset %u", attr->handle, data->offset);
|
||||||
|
|
||||||
/* Check for write support */
|
|
||||||
if (!attr->write) {
|
|
||||||
data->err = BT_ATT_ERR_WRITE_NOT_PERMITTED;
|
|
||||||
return BT_GATT_ITER_STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check attribute permissions */
|
/* Check attribute permissions */
|
||||||
data->err = check_perm(data->conn, attr, BT_GATT_PERM_WRITE_MASK);
|
data->err = check_perm(data->conn, attr, BT_GATT_PERM_WRITE_MASK);
|
||||||
if (data->err) {
|
if (data->err) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue