Skip to content

Commit

Permalink
shared/gatt: Prevent security level change for PTS GATT tests
Browse files Browse the repository at this point in the history
Some PTS GATT tests like GATT/CL/GAR/BI-04-C request to be able to get the
security error and do not try to change the security level.

This commit adds the ability to prevent to change the security level for
an operation.
  • Loading branch information
fdanis-oss authored and Vudentz committed Jan 25, 2024
1 parent 2e2e500 commit 6c15afe
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/shared/att.c
Expand Up @@ -2042,3 +2042,29 @@ bool bt_att_has_crypto(struct bt_att *att)

return att->crypto ? true : false;
}

bool bt_att_set_retry(struct bt_att *att, unsigned int id, bool retry)
{
struct att_send_op *op;

if (!id)
return false;

op = queue_find(att->req_queue, match_op_id, UINT_TO_PTR(id));
if (op)
goto done;

op = queue_find(att->ind_queue, match_op_id, UINT_TO_PTR(id));
if (op)
goto done;

op = queue_find(att->write_queue, match_op_id, UINT_TO_PTR(id));

done:
if (!op)
return false;

op->retry = !retry;

return true;
}
1 change: 1 addition & 0 deletions src/shared/att.h
Expand Up @@ -110,3 +110,4 @@ bool bt_att_set_local_key(struct bt_att *att, uint8_t sign_key[16],
bool bt_att_set_remote_key(struct bt_att *att, uint8_t sign_key[16],
bt_att_counter_func_t func, void *user_data);
bool bt_att_has_crypto(struct bt_att *att);
bool bt_att_set_retry(struct bt_att *att, unsigned int id, bool retry);
19 changes: 19 additions & 0 deletions src/shared/gatt-client.c
Expand Up @@ -3818,3 +3818,22 @@ bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client,

return false;
}

bool bt_gatt_client_set_retry(struct bt_gatt_client *client,
unsigned int id,
bool retry)
{
struct request *req;

if (!client || !id)
return false;

req = queue_find(client->pending_requests, match_req_id,
UINT_TO_PTR(id));
if (!req)
return false;

bt_att_set_retry(client->att, req->att_id, retry);

return true;
}
3 changes: 3 additions & 0 deletions src/shared/gatt-client.h
Expand Up @@ -134,3 +134,6 @@ unsigned int bt_gatt_client_idle_register(struct bt_gatt_client *client,
bt_gatt_client_destroy_func_t destroy);
bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client,
unsigned int id);
bool bt_gatt_client_set_retry(struct bt_gatt_client *client,
unsigned int id,
bool retry);

0 comments on commit 6c15afe

Please sign in to comment.