Skip to content

Commit

Permalink
Bluetooth: L2CAP: Refactor handling connection response
Browse files Browse the repository at this point in the history
Adds internal helper routine sending response to connection request when
BR/EDR CoC channel operates in acceptor role. The routine additionally
can drive the response 'result' value for failure reasons.
Use it then to adjust 'l2cap_br_conn_pend' function to accept remote's
connection request.

Change-Id: I906e07e30939c57b206e9806426897f6e4f2b3dd
Signed-off-by: Arkadiusz Lichwa <[email protected]>
  • Loading branch information
xpuarli authored and Johan Hedberg committed Oct 21, 2016
1 parent 96c1169 commit d99e0c3
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions net/bluetooth/l2cap_br.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,11 +1528,44 @@ static void l2cap_br_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
}
}

static void l2cap_br_conn_pend(struct bt_l2cap_chan *chan, uint8_t status)
static int l2cap_br_conn_req_reply(struct bt_l2cap_chan *chan, uint16_t result)
{
struct net_buf *buf;
struct bt_l2cap_conn_rsp *rsp;
struct bt_l2cap_sig_hdr *hdr;

if (!atomic_test_bit(BR_CHAN(chan)->flags, L2CAP_FLAG_CONN_ACCEPTOR)) {
return -ESRCH;
}

/* Send response to connection request only when in acceptor role */
buf = bt_l2cap_create_pdu(&br_sig, 0);
if (!buf) {
BT_ERR("No buffers for PDU");
return -ENOMEM;
}

hdr = net_buf_add(buf, sizeof(*hdr));
hdr->code = BT_L2CAP_CONN_RSP;
hdr->ident = chan->ident;
hdr->len = sys_cpu_to_le16(sizeof(*rsp));

rsp = net_buf_add(buf, sizeof(*rsp));
rsp->dcid = sys_cpu_to_le16(BR_CHAN(chan)->rx.cid);
rsp->scid = sys_cpu_to_le16(BR_CHAN(chan)->tx.cid);
rsp->status = sys_cpu_to_le16(BT_L2CAP_SUCCESS);
rsp->result = sys_cpu_to_le16(result);

bt_l2cap_send(chan->conn, BT_L2CAP_CID_BR_SIG, buf);
chan->ident = 0;

return 0;
}

static void l2cap_br_conn_pend(struct bt_l2cap_chan *chan, uint8_t status)
{
struct net_buf *buf;
struct bt_l2cap_sig_hdr *hdr;
struct bt_l2cap_conn_req *req;

if (chan->state != BT_L2CAP_CONNECT) {
Expand All @@ -1550,28 +1583,7 @@ static void l2cap_br_conn_pend(struct bt_l2cap_chan *chan, uint8_t status)
* For incoming connection state send confirming outstanding
* response and initiate configuration request.
*/
if (atomic_test_bit(BR_CHAN(chan)->flags, L2CAP_FLAG_CONN_ACCEPTOR)) {
buf = bt_l2cap_create_pdu(&br_sig, 0);
if (!buf) {
BT_ERR("No buffers for PDU");
return;
}

hdr = net_buf_add(buf, sizeof(*hdr));
hdr->code = BT_L2CAP_CONN_RSP;
hdr->ident = chan->ident;
hdr->len = sys_cpu_to_le16(sizeof(*rsp));

rsp = net_buf_add(buf, sizeof(*rsp));
memset(rsp, 0, sizeof(*rsp));

rsp->dcid = sys_cpu_to_le16(BR_CHAN(chan)->rx.cid);
rsp->scid = sys_cpu_to_le16(BR_CHAN(chan)->tx.cid);
rsp->result = BT_L2CAP_SUCCESS;

bt_l2cap_send(chan->conn, BT_L2CAP_CID_BR_SIG, buf);

chan->ident = 0;
if (l2cap_br_conn_req_reply(chan, BT_L2CAP_SUCCESS) == 0) {
l2cap_br_state_set(chan, BT_L2CAP_CONFIG);
/*
* Initialize config request since remote needs to know
Expand Down

0 comments on commit d99e0c3

Please sign in to comment.