Skip to content

Commit 0bd49fc

Browse files
jhedbergholtmann
authored andcommitted
Bluetooth: Track both local and remote L2CAP fixed channel mask
To pave the way for future fixed channels to be added easily we should track both the local and remote mask on a per-L2CAP connection (struct l2cap_conn) basis. So far the code has used a global variable in a racy way which anyway needs fixing. This patch renames the existing conn->fixed_chan_mask that tracked the remote mask to conn->remote_fixed_chan and adds a new variable conn->local_fixed_chan to track the local mask. Since the HS support info is now available in the local mask we can remove the conn->hs_enabled variable. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent f6af675 commit 0bd49fc

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

‎include/net/bluetooth/l2cap.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ struct l2cap_conn {
619619
unsigned int mtu;
620620

621621
__u32 feat_mask;
622-
__u8 fixed_chan_mask;
623-
bool hs_enabled;
622+
__u8 remote_fixed_chan;
623+
__u8 local_fixed_chan;
624624

625625
__u8 info_state;
626626
__u8 info_ident;

‎net/bluetooth/l2cap_core.c‎

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
bool disable_ertm;
4747

4848
static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN | L2CAP_FEAT_UCD;
49-
static u8 l2cap_fixed_chan[8] = { L2CAP_FC_SIG_BREDR | L2CAP_FC_CONNLESS, };
5049

5150
static LIST_HEAD(chan_list);
5251
static DEFINE_RWLOCK(chan_list_lock);
@@ -1120,10 +1119,10 @@ static bool __amp_capable(struct l2cap_chan *chan)
11201119
struct hci_dev *hdev;
11211120
bool amp_available = false;
11221121

1123-
if (!conn->hs_enabled)
1122+
if (!(conn->local_fixed_chan & L2CAP_FC_A2MP))
11241123
return false;
11251124

1126-
if (!(conn->fixed_chan_mask & L2CAP_FC_A2MP))
1125+
if (!(conn->remote_fixed_chan & L2CAP_FC_A2MP))
11271126
return false;
11281127

11291128
read_lock(&hci_dev_list_lock);
@@ -3096,12 +3095,14 @@ static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask)
30963095

30973096
static inline bool __l2cap_ews_supported(struct l2cap_conn *conn)
30983097
{
3099-
return conn->hs_enabled && conn->feat_mask & L2CAP_FEAT_EXT_WINDOW;
3098+
return ((conn->local_fixed_chan & L2CAP_FC_A2MP) &&
3099+
(conn->feat_mask & L2CAP_FEAT_EXT_WINDOW));
31003100
}
31013101

31023102
static inline bool __l2cap_efs_supported(struct l2cap_conn *conn)
31033103
{
3104-
return conn->hs_enabled && conn->feat_mask & L2CAP_FEAT_EXT_FLOW;
3104+
return ((conn->local_fixed_chan & L2CAP_FC_A2MP) &&
3105+
(conn->feat_mask & L2CAP_FEAT_EXT_FLOW));
31053106
}
31063107

31073108
static void __l2cap_set_ertm_timeouts(struct l2cap_chan *chan,
@@ -3330,7 +3331,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
33303331
break;
33313332

33323333
case L2CAP_CONF_EWS:
3333-
if (!chan->conn->hs_enabled)
3334+
if (!(chan->conn->local_fixed_chan & L2CAP_FC_A2MP))
33343335
return -ECONNREFUSED;
33353336

33363337
set_bit(FLAG_EXT_CTRL, &chan->flags);
@@ -4334,7 +4335,7 @@ static inline int l2cap_information_req(struct l2cap_conn *conn,
43344335
if (!disable_ertm)
43354336
feat_mask |= L2CAP_FEAT_ERTM | L2CAP_FEAT_STREAMING
43364337
| L2CAP_FEAT_FCS;
4337-
if (conn->hs_enabled)
4338+
if (conn->local_fixed_chan & L2CAP_FC_A2MP)
43384339
feat_mask |= L2CAP_FEAT_EXT_FLOW
43394340
| L2CAP_FEAT_EXT_WINDOW;
43404341

@@ -4345,14 +4346,10 @@ static inline int l2cap_information_req(struct l2cap_conn *conn,
43454346
u8 buf[12];
43464347
struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) buf;
43474348

4348-
if (conn->hs_enabled)
4349-
l2cap_fixed_chan[0] |= L2CAP_FC_A2MP;
4350-
else
4351-
l2cap_fixed_chan[0] &= ~L2CAP_FC_A2MP;
4352-
43534349
rsp->type = cpu_to_le16(L2CAP_IT_FIXED_CHAN);
43544350
rsp->result = cpu_to_le16(L2CAP_IR_SUCCESS);
4355-
memcpy(rsp->data, l2cap_fixed_chan, sizeof(l2cap_fixed_chan));
4351+
rsp->data[0] = conn->local_fixed_chan;
4352+
memset(rsp->data + 1, 0, 7);
43564353
l2cap_send_cmd(conn, cmd->ident, L2CAP_INFO_RSP, sizeof(buf),
43574354
buf);
43584355
} else {
@@ -4418,7 +4415,7 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn,
44184415
break;
44194416

44204417
case L2CAP_IT_FIXED_CHAN:
4421-
conn->fixed_chan_mask = rsp->data[0];
4418+
conn->remote_fixed_chan = rsp->data[0];
44224419
conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_DONE;
44234420
conn->info_ident = 0;
44244421

@@ -4442,7 +4439,7 @@ static int l2cap_create_channel_req(struct l2cap_conn *conn,
44424439
if (cmd_len != sizeof(*req))
44434440
return -EPROTO;
44444441

4445-
if (!conn->hs_enabled)
4442+
if (!(conn->local_fixed_chan & L2CAP_FC_A2MP))
44464443
return -EINVAL;
44474444

44484445
psm = le16_to_cpu(req->psm);
@@ -4872,7 +4869,7 @@ static inline int l2cap_move_channel_req(struct l2cap_conn *conn,
48724869

48734870
BT_DBG("icid 0x%4.4x, dest_amp_id %d", icid, req->dest_amp_id);
48744871

4875-
if (!conn->hs_enabled)
4872+
if (!(conn->local_fixed_chan & L2CAP_FC_A2MP))
48764873
return -EINVAL;
48774874

48784875
chan = l2cap_get_chan_by_dcid(conn, icid);
@@ -6964,9 +6961,11 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon)
69646961

69656962
conn->feat_mask = 0;
69666963

6967-
if (hcon->type == ACL_LINK)
6968-
conn->hs_enabled = test_bit(HCI_HS_ENABLED,
6969-
&hcon->hdev->dev_flags);
6964+
conn->local_fixed_chan = L2CAP_FC_SIG_BREDR | L2CAP_FC_CONNLESS;
6965+
6966+
if (hcon->type == ACL_LINK &&
6967+
test_bit(HCI_HS_ENABLED, &hcon->hdev->dev_flags))
6968+
conn->local_fixed_chan |= L2CAP_FC_A2MP;
69706969

69716970
mutex_init(&conn->ident_lock);
69726971
mutex_init(&conn->chan_lock);

0 commit comments

Comments
 (0)