Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: HFP: Fix session pointer invalid issue #69591

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions subsys/bluetooth/host/hfp_hf.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void ag_indicator_handle_values(struct at_client *hf_at, uint32_t index,
uint32_t value)
{
struct bt_hfp_hf *hf = CONTAINER_OF(hf_at, struct bt_hfp_hf, at);
struct bt_conn *conn = hf->rfcomm_dlc.session->br_chan.chan.conn;
struct bt_conn *conn = hf->acl;

LOG_DBG("Index :%u, Value :%u", index, value);

Expand Down Expand Up @@ -351,7 +351,7 @@ int ciev_handle(struct at_client *hf_at)
int ring_handle(struct at_client *hf_at)
{
struct bt_hfp_hf *hf = CONTAINER_OF(hf_at, struct bt_hfp_hf, at);
struct bt_conn *conn = hf->rfcomm_dlc.session->br_chan.chan.conn;
struct bt_conn *conn = hf->acl;

if (bt_hf->ring_indication) {
bt_hf->ring_indication(conn);
Expand Down Expand Up @@ -405,7 +405,7 @@ int cmd_complete(struct at_client *hf_at, enum at_result result,
enum at_cme cme_err)
{
struct bt_hfp_hf *hf = CONTAINER_OF(hf_at, struct bt_hfp_hf, at);
struct bt_conn *conn = hf->rfcomm_dlc.session->br_chan.chan.conn;
struct bt_conn *conn = hf->acl;
struct bt_hfp_hf_cmd_complete cmd = { 0 };

LOG_DBG("");
Expand Down Expand Up @@ -448,7 +448,7 @@ int cmee_finish(struct at_client *hf_at, enum at_result result,
static void slc_completed(struct at_client *hf_at)
{
struct bt_hfp_hf *hf = CONTAINER_OF(hf_at, struct bt_hfp_hf, at);
struct bt_conn *conn = hf->rfcomm_dlc.session->br_chan.chan.conn;
struct bt_conn *conn = hf->acl;

if (bt_hf->connected) {
bt_hf->connected(conn);
Expand Down Expand Up @@ -561,7 +561,7 @@ static struct bt_hfp_hf *bt_hfp_hf_lookup_bt_conn(struct bt_conn *conn)
for (i = 0; i < ARRAY_SIZE(bt_hfp_hf_pool); i++) {
struct bt_hfp_hf *hf = &bt_hfp_hf_pool[i];

if (hf->rfcomm_dlc.session->br_chan.chan.conn == conn) {
if (hf->acl == conn) {
return hf;
}
}
Expand Down Expand Up @@ -622,7 +622,8 @@ static void hfp_hf_connected(struct bt_rfcomm_dlc *dlc)

static void hfp_hf_disconnected(struct bt_rfcomm_dlc *dlc)
{
struct bt_conn *conn = dlc->session->br_chan.chan.conn;
struct bt_hfp_hf *hf = CONTAINER_OF(dlc, struct bt_hfp_hf, rfcomm_dlc);
struct bt_conn *conn = hf->acl;

LOG_DBG("hf disconnected!");
if (bt_hf->disconnected) {
Expand Down Expand Up @@ -658,6 +659,7 @@ static int bt_hfp_hf_accept(struct bt_conn *conn, struct bt_rfcomm_dlc **dlc)
continue;
}

hf->acl = conn;
hf->at.buf = hf->hf_buffer;
hf->at.buf_max_len = HF_MAX_BUF_LEN;

Expand Down
2 changes: 2 additions & 0 deletions subsys/bluetooth/host/hfp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

struct bt_hfp_hf {
struct bt_rfcomm_dlc rfcomm_dlc;
/* ACL connection handle */
struct bt_conn *acl;
char hf_buffer[HF_MAX_BUF_LEN];
struct at_client at;
uint32_t hf_features;
Expand Down
Loading