Skip to content

Commit

Permalink
Bluetooth: L2CAP: Refactor CoC CID ranges
Browse files Browse the repository at this point in the history
Adds helper defines to mark valid CID values and ranges for CoC on BR/EDR
and LE.

Change-Id: Ib2db3a6a8f4b6565920f47b520e27e3b8cc6c85c
Signed-off-by: Arkadiusz Lichwa <[email protected]>
  • Loading branch information
xpuarli authored and Johan Hedberg committed Oct 21, 2016
1 parent 1a1843d commit cdebad8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
13 changes: 7 additions & 6 deletions net/bluetooth/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
#define L2CAP_LE_MAX_CREDITS (CONFIG_BLUETOOTH_ACL_IN_COUNT - 1)
#define L2CAP_LE_CREDITS_THRESHOLD (L2CAP_LE_MAX_CREDITS / 2)

#define L2CAP_LE_DYN_CID_START 0x0040
#define L2CAP_LE_DYN_CID_END 0x007f
#define L2CAP_LE_CID_DYN_START 0x0040
#define L2CAP_LE_CID_DYN_END 0x007f
#define L2CAP_LE_CID_IS_DYN(_cid) \
(_cid >= L2CAP_LE_CID_DYN_START && _cid <= L2CAP_LE_CID_DYN_END)

#define L2CAP_LE_PSM_START 0x0001
#define L2CAP_LE_PSM_END 0x00ff
Expand Down Expand Up @@ -136,7 +138,7 @@ static struct bt_l2cap_le_chan *l2cap_chan_alloc_cid(struct bt_conn *conn,
return ch;
}

for (cid = L2CAP_LE_DYN_CID_START; cid <= L2CAP_LE_DYN_CID_END; cid++) {
for (cid = L2CAP_LE_CID_DYN_START; cid <= L2CAP_LE_CID_DYN_END; cid++) {
if (ch && !bt_l2cap_le_lookup_rx_cid(conn, cid)) {
ch->rx.cid = cid;
return ch;
Expand Down Expand Up @@ -605,7 +607,7 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident,

/* TODO: Add security check */

if (scid < L2CAP_LE_DYN_CID_START || scid > L2CAP_LE_DYN_CID_END) {
if (!L2CAP_LE_CID_IS_DYN(scid)) {
rsp->result = sys_cpu_to_le16(BT_L2CAP_ERR_INVALID_SCID);
goto rsp;
}
Expand Down Expand Up @@ -1102,8 +1104,7 @@ static void l2cap_chan_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
#if defined(CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL)
struct bt_l2cap_le_chan *ch = BT_L2CAP_LE_CHAN(chan);

if (ch->rx.cid >= L2CAP_LE_DYN_CID_START &&
ch->rx.cid <= L2CAP_LE_DYN_CID_END) {
if (L2CAP_LE_CID_IS_DYN(ch->rx.cid)) {
l2cap_chan_le_recv(ch, buf);
return;
}
Expand Down
12 changes: 7 additions & 5 deletions net/bluetooth/l2cap_br.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
#define L2CAP_BR_PSM_START 0x0001
#define L2CAP_BR_PSM_END 0xffff

#define L2CAP_BR_DYN_CID_START 0x0040
#define L2CAP_BR_DYN_CID_END 0xffff
#define L2CAP_BR_CID_DYN_START 0x0040
#define L2CAP_BR_CID_DYN_END 0xffff
#define L2CAP_BR_CID_IS_DYN(_cid) \
(_cid >= L2CAP_BR_CID_DYN_START && _cid <= L2CAP_BR_CID_DYN_END)

#define L2CAP_BR_MIN_MTU 48
#define L2CAP_BR_DEFAULT_MTU 672
Expand Down Expand Up @@ -240,7 +242,7 @@ l2cap_br_chan_alloc_cid(struct bt_conn *conn, struct bt_l2cap_chan *chan)
return ch;
}

for (cid = L2CAP_BR_DYN_CID_START; cid <= L2CAP_BR_DYN_CID_END; cid++) {
for (cid = L2CAP_BR_CID_DYN_START; cid <= L2CAP_BR_CID_DYN_END; cid++) {
if (!bt_l2cap_br_lookup_rx_cid(conn, cid)) {
ch->rx.cid = cid;
return ch;
Expand Down Expand Up @@ -816,7 +818,7 @@ static void l2cap_br_conn_req(struct bt_l2cap_br *l2cap, uint8_t ident,
goto done;
}

if (scid < L2CAP_BR_DYN_CID_START || scid > L2CAP_BR_DYN_CID_END) {
if (!L2CAP_BR_CID_IS_DYN(scid)) {
result = BT_L2CAP_ERR_INVALID_SCID;
goto done;
}
Expand Down Expand Up @@ -1610,7 +1612,7 @@ static void check_fixed_channel(struct bt_l2cap_chan *chan)
{
struct bt_l2cap_br_chan *br_chan = BR_CHAN(chan);

if (br_chan->rx.cid < L2CAP_BR_DYN_CID_START) {
if (br_chan->rx.cid < L2CAP_BR_CID_DYN_START) {
connect_fixed_channel(br_chan);
}
}
Expand Down

0 comments on commit cdebad8

Please sign in to comment.