Skip to content

Commit 52862dc

Browse files
PavelVPVcfriedt
authored andcommitted
bluetooth: host: move bt_gatt_authorization_cb_register to gatt.c
This function logically belongs to gatt.c as it is GATT API. Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 65fae0a commit 52862dc

File tree

3 files changed

+59
-58
lines changed

3 files changed

+59
-58
lines changed

subsys/bluetooth/host/att.c

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ static uint16_t bt_att_mtu(struct bt_att_chan *chan)
143143
return MIN(chan->chan.rx.mtu, chan->chan.tx.mtu);
144144
}
145145

146-
/* Descriptor of application-specific authorization callbacks that are used
147-
* with the CONFIG_BT_GATT_AUTHORIZATION_CUSTOM Kconfig enabled.
148-
*/
149-
static const struct bt_gatt_authorization_cb *authorization_cb;
150-
151146
/* ATT connection specific data */
152147
struct bt_att {
153148
struct bt_conn *conn;
@@ -1350,20 +1345,6 @@ struct read_type_data {
13501345
typedef bool (*attr_read_cb)(struct net_buf *buf, ssize_t read,
13511346
void *user_data);
13521347

1353-
static bool attr_read_authorize(struct bt_conn *conn,
1354-
const struct bt_gatt_attr *attr)
1355-
{
1356-
if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) {
1357-
return true;
1358-
}
1359-
1360-
if (!authorization_cb || !authorization_cb->read_authorize) {
1361-
return true;
1362-
}
1363-
1364-
return authorization_cb->read_authorize(conn, attr);
1365-
}
1366-
13671348
static bool attr_read_type_cb(struct net_buf *frag, ssize_t read,
13681349
void *user_data)
13691350
{
@@ -1474,7 +1455,7 @@ static uint8_t read_type_cb(const struct bt_gatt_attr *attr, uint16_t handle,
14741455
}
14751456

14761457
/* Check the attribute authorization logic */
1477-
if (!attr_read_authorize(conn, attr)) {
1458+
if (!bt_gatt_attr_read_authorize(conn, attr)) {
14781459
data->err = BT_ATT_ERR_AUTHORIZATION;
14791460
return BT_GATT_ITER_STOP;
14801461
}
@@ -1630,7 +1611,7 @@ static uint8_t read_cb(const struct bt_gatt_attr *attr, uint16_t handle,
16301611
}
16311612

16321613
/* Check the attribute authorization logic */
1633-
if (!attr_read_authorize(conn, attr)) {
1614+
if (!bt_gatt_attr_read_authorize(conn, attr)) {
16341615
data->err = BT_ATT_ERR_AUTHORIZATION;
16351616
return BT_GATT_ITER_STOP;
16361617
}
@@ -1801,7 +1782,7 @@ static uint8_t read_vl_cb(const struct bt_gatt_attr *attr, uint16_t handle,
18011782
}
18021783

18031784
/* Check the attribute authorization logic */
1804-
if (!attr_read_authorize(conn, attr)) {
1785+
if (!bt_gatt_attr_read_authorize(conn, attr)) {
18051786
data->err = BT_ATT_ERR_AUTHORIZATION;
18061787
return BT_GATT_ITER_STOP;
18071788
}
@@ -2050,20 +2031,6 @@ struct write_data {
20502031
uint8_t err;
20512032
};
20522033

2053-
static bool attr_write_authorize(struct bt_conn *conn,
2054-
const struct bt_gatt_attr *attr)
2055-
{
2056-
if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) {
2057-
return true;
2058-
}
2059-
2060-
if (!authorization_cb || !authorization_cb->write_authorize) {
2061-
return true;
2062-
}
2063-
2064-
return authorization_cb->write_authorize(conn, attr);
2065-
}
2066-
20672034
static uint8_t write_cb(const struct bt_gatt_attr *attr, uint16_t handle,
20682035
void *user_data)
20692036
{
@@ -2081,7 +2048,7 @@ static uint8_t write_cb(const struct bt_gatt_attr *attr, uint16_t handle,
20812048
}
20822049

20832050
/* Check the attribute authorization logic */
2084-
if (!attr_write_authorize(data->conn, attr)) {
2051+
if (!bt_gatt_attr_write_authorize(data->conn, attr)) {
20852052
data->err = BT_ATT_ERR_AUTHORIZATION;
20862053
return BT_GATT_ITER_STOP;
20872054
}
@@ -2200,7 +2167,7 @@ static uint8_t prep_write_cb(const struct bt_gatt_attr *attr, uint16_t handle,
22002167
}
22012168

22022169
/* Check the attribute authorization logic */
2203-
if (!attr_write_authorize(data->conn, attr)) {
2170+
if (!bt_gatt_attr_write_authorize(data->conn, attr)) {
22042171
data->err = BT_ATT_ERR_AUTHORIZATION;
22052172
return BT_GATT_ITER_STOP;
22062173
}
@@ -4169,23 +4136,3 @@ bool bt_att_chan_opt_valid(struct bt_conn *conn, enum bt_att_chan_opt chan_opt)
41694136

41704137
return true;
41714138
}
4172-
4173-
int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb)
4174-
{
4175-
if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) {
4176-
return -ENOSYS;
4177-
}
4178-
4179-
if (!cb) {
4180-
authorization_cb = NULL;
4181-
return 0;
4182-
}
4183-
4184-
if (authorization_cb) {
4185-
return -EALREADY;
4186-
}
4187-
4188-
authorization_cb = cb;
4189-
4190-
return 0;
4191-
}

subsys/bluetooth/host/gatt.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6590,3 +6590,54 @@ void bt_gatt_req_set_mtu(struct bt_att_req *req, uint16_t mtu)
65906590
* request types if needed.
65916591
*/
65926592
}
6593+
6594+
/* Descriptor of application-specific authorization callbacks that are used
6595+
* with the CONFIG_BT_GATT_AUTHORIZATION_CUSTOM Kconfig enabled.
6596+
*/
6597+
static const struct bt_gatt_authorization_cb *authorization_cb;
6598+
6599+
bool bt_gatt_attr_read_authorize(struct bt_conn *conn, const struct bt_gatt_attr *attr)
6600+
{
6601+
if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) {
6602+
return true;
6603+
}
6604+
6605+
if (!authorization_cb || !authorization_cb->read_authorize) {
6606+
return true;
6607+
}
6608+
6609+
return authorization_cb->read_authorize(conn, attr);
6610+
}
6611+
6612+
bool bt_gatt_attr_write_authorize(struct bt_conn *conn, const struct bt_gatt_attr *attr)
6613+
{
6614+
if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) {
6615+
return true;
6616+
}
6617+
6618+
if (!authorization_cb || !authorization_cb->write_authorize) {
6619+
return true;
6620+
}
6621+
6622+
return authorization_cb->write_authorize(conn, attr);
6623+
}
6624+
6625+
int bt_gatt_authorization_cb_register(const struct bt_gatt_authorization_cb *cb)
6626+
{
6627+
if (!IS_ENABLED(CONFIG_BT_GATT_AUTHORIZATION_CUSTOM)) {
6628+
return -ENOSYS;
6629+
}
6630+
6631+
if (!cb) {
6632+
authorization_cb = NULL;
6633+
return 0;
6634+
}
6635+
6636+
if (authorization_cb) {
6637+
return -EALREADY;
6638+
}
6639+
6640+
authorization_cb = cb;
6641+
6642+
return 0;
6643+
}

subsys/bluetooth/host/gatt_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ struct bt_gatt_attr;
6868
/* Check attribute permission */
6969
uint8_t bt_gatt_check_perm(struct bt_conn *conn, const struct bt_gatt_attr *attr,
7070
uint16_t mask);
71+
72+
bool bt_gatt_attr_read_authorize(struct bt_conn *conn, const struct bt_gatt_attr *attr);
73+
bool bt_gatt_attr_write_authorize(struct bt_conn *conn, const struct bt_gatt_attr *attr);

0 commit comments

Comments
 (0)