Skip to content

Commit

Permalink
Bluetooth: RFCOMM: Introduce helper to get session
Browse files Browse the repository at this point in the history
This is to avoid code duplication while implementing outgoing
connection.

This also moves setting initiator flag while allocating, than
doing it when SABM is received.

Change-Id: I8e811c995bf0eaa0bd24715e2e96d8a578a79c5d
Signed-off-by: Jaganath Kanakkassery <[email protected]>
  • Loading branch information
jkanakkx authored and Johan Hedberg committed Nov 4, 2016
1 parent 2eba256 commit e3c258e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions subsys/bluetooth/host/rfcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@ static void rfcomm_dlc_drop(struct bt_rfcomm_dlc *dlc)
static void rfcomm_handle_sabm(struct bt_rfcomm_session *session, uint8_t dlci)
{
if (!dlci) {
session->role = BT_RFCOMM_ROLE_ACCEPTOR;

if (rfcomm_send_ua(session, dlci) < 0) {
return;
}
Expand Down Expand Up @@ -951,7 +949,7 @@ static void rfcomm_encrypt_change(struct bt_l2cap_chan *chan,
}
}

static int rfcomm_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
static struct bt_rfcomm_session *rfcomm_session_new(bt_rfcomm_role_t role)
{
int i;
static struct bt_l2cap_chan_ops ops = {
Expand All @@ -961,8 +959,6 @@ static int rfcomm_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
.encrypt_change = rfcomm_encrypt_change,
};

BT_DBG("conn %p handle %u", conn, conn->handle);

for (i = 0; i < ARRAY_SIZE(bt_rfcomm_pool); i++) {
struct bt_rfcomm_session *session = &bt_rfcomm_pool[i];

Expand All @@ -975,7 +971,22 @@ static int rfcomm_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
session->br_chan.chan.ops = &ops;
session->br_chan.rx.mtu = CONFIG_BLUETOOTH_RFCOMM_L2CAP_MTU;
session->state = BT_RFCOMM_STATE_INIT;
session->role = role;

return session;
}

return NULL;
}

static int rfcomm_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
{
struct bt_rfcomm_session *session;

BT_DBG("conn %p", conn);

session = rfcomm_session_new(BT_RFCOMM_ROLE_ACCEPTOR);
if (session) {
*chan = &session->br_chan.chan;
return 0;
}
Expand Down

0 comments on commit e3c258e

Please sign in to comment.