Bluetooth: has: Allocate context for client once link is encrypted
The HAS sends notifications to paired devices. Thus the client context has to be initialized once the link has required security. Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
parent
a4d9c82fca
commit
cf59606883
1 changed files with 22 additions and 2 deletions
|
@ -181,6 +181,22 @@ static struct has_client *client_get(struct bt_conn *conn)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err)
|
||||||
|
{
|
||||||
|
struct has_client *client;
|
||||||
|
|
||||||
|
BT_DBG("conn %p level %d err %d", (void *)conn, level, err);
|
||||||
|
|
||||||
|
if (err != BT_SECURITY_ERR_SUCCESS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
client = client_get_or_new(conn);
|
||||||
|
if (unlikely(!client)) {
|
||||||
|
BT_ERR("Failed to allocate client");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void disconnected(struct bt_conn *conn, uint8_t reason)
|
static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||||
{
|
{
|
||||||
struct has_client *client;
|
struct has_client *client;
|
||||||
|
@ -195,6 +211,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
||||||
|
|
||||||
BT_CONN_CB_DEFINE(conn_cb) = {
|
BT_CONN_CB_DEFINE(conn_cb) = {
|
||||||
.disconnected = disconnected,
|
.disconnected = disconnected,
|
||||||
|
.security_changed = security_changed,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef uint8_t (*preset_func_t)(const struct has_preset *preset, void *user_data);
|
typedef uint8_t (*preset_func_t)(const struct has_preset *preset, void *user_data);
|
||||||
|
@ -492,6 +509,11 @@ static uint8_t handle_read_preset_req(struct bt_conn *conn, struct net_buf_simpl
|
||||||
return BT_ATT_ERR_CCC_IMPROPER_CONF;
|
return BT_ATT_ERR_CCC_IMPROPER_CONF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client = client_get(conn);
|
||||||
|
if (!client) {
|
||||||
|
return BT_ATT_ERR_UNLIKELY;
|
||||||
|
}
|
||||||
|
|
||||||
req = net_buf_simple_pull_mem(buf, sizeof(*req));
|
req = net_buf_simple_pull_mem(buf, sizeof(*req));
|
||||||
|
|
||||||
BT_DBG("start_index %d num_presets %d", req->start_index, req->num_presets);
|
BT_DBG("start_index %d num_presets %d", req->start_index, req->num_presets);
|
||||||
|
@ -503,8 +525,6 @@ static uint8_t handle_read_preset_req(struct bt_conn *conn, struct net_buf_simpl
|
||||||
return BT_ATT_ERR_OUT_OF_RANGE;
|
return BT_ATT_ERR_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
client = client_get_or_new(conn);
|
|
||||||
|
|
||||||
/* Reject if already in progress */
|
/* Reject if already in progress */
|
||||||
if (read_presets_req_is_pending(client)) {
|
if (read_presets_req_is_pending(client)) {
|
||||||
return BT_HAS_ERR_OPERATION_NOT_POSSIBLE;
|
return BT_HAS_ERR_OPERATION_NOT_POSSIBLE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue