summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorSzymon Janc <ext.szymon.janc@tieto.com>2016-09-28 16:59:34 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2016-10-16 09:00:57 +0300
commit27731ce222f7baf81d897d378c9785fa056b9fdc (patch)
tree2e11f9b8f4ed2e2885fbb917766010a0b900aa7b /net
parente4f2df013a4851174e34aa776a529fd88d82269e (diff)
Bluetooth: L2CAP: Move BR/EDR specific code to l2cap_br.c
This is in preparation for proper handling of fixed channels over BR/EDR. Change-Id: I506c365377d5d6bc74f3cf6d257be43c17f22437 Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
Diffstat (limited to 'net')
-rw-r--r--net/bluetooth/l2cap.c35
-rw-r--r--net/bluetooth/l2cap_br.c26
-rw-r--r--net/bluetooth/l2cap_internal.h3
3 files changed, 39 insertions, 25 deletions
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 28645ceb3..366e1b0a0 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -1052,18 +1052,9 @@ static void l2cap_chan_le_recv(struct bt_l2cap_le_chan *chan,
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;
-
- switch (chan->conn->type) {
- case BT_CONN_TYPE_LE:
- ch = BT_L2CAP_LE_CHAN(chan);
- break;
- default:
- ch = NULL;
- break;
- }
+ struct bt_l2cap_le_chan *ch = BT_L2CAP_LE_CHAN(chan);
- if (ch && ch->rx.cid >= L2CAP_LE_DYN_CID_START &&
+ if (ch->rx.cid >= L2CAP_LE_DYN_CID_START &&
ch->rx.cid <= L2CAP_LE_DYN_CID_END) {
l2cap_chan_le_recv(ch, buf);
return;
@@ -1081,6 +1072,13 @@ void bt_l2cap_recv(struct bt_conn *conn, struct net_buf *buf)
struct bt_l2cap_chan *chan;
uint16_t cid;
+#if defined(CONFIG_BLUETOOTH_BREDR)
+ if (conn->type == BT_CONN_TYPE_BR) {
+ bt_l2cap_br_recv(conn, buf);
+ return;
+ }
+#endif /* CONFIG_BLUETOOTH_BREDR */
+
if (buf->len < sizeof(*hdr)) {
BT_ERR("Too small L2CAP PDU received");
net_buf_unref(buf);
@@ -1092,20 +1090,7 @@ void bt_l2cap_recv(struct bt_conn *conn, struct net_buf *buf)
BT_DBG("Packet for CID %u len %u", cid, buf->len);
- switch (conn->type) {
- case BT_CONN_TYPE_LE:
- chan = bt_l2cap_le_lookup_rx_cid(conn, cid);
- break;
-#if defined(CONFIG_BLUETOOTH_BREDR)
- case BT_CONN_TYPE_BR:
- chan = bt_l2cap_br_lookup_rx_cid(conn, cid);
- break;
-#endif /* CONFIG_BLUETOOTH_BREDR */
- default:
- chan = NULL;
- break;
- }
-
+ chan = bt_l2cap_le_lookup_rx_cid(conn, cid);
if (!chan) {
BT_WARN("Ignoring data for unknown CID 0x%04x", cid);
net_buf_unref(buf);
diff --git a/net/bluetooth/l2cap_br.c b/net/bluetooth/l2cap_br.c
index 1d72d61e0..15f640d1a 100644
--- a/net/bluetooth/l2cap_br.c
+++ b/net/bluetooth/l2cap_br.c
@@ -1570,6 +1570,32 @@ void l2cap_br_encrypt_change(struct bt_conn *conn, uint8_t hci_status)
}
}
+void bt_l2cap_br_recv(struct bt_conn *conn, struct net_buf *buf)
+{
+ struct bt_l2cap_hdr *hdr = (void *)buf->data;
+ struct bt_l2cap_chan *chan;
+ uint16_t cid;
+
+ if (buf->len < sizeof(*hdr)) {
+ BT_ERR("Too small L2CAP PDU received");
+ net_buf_unref(buf);
+ return;
+ }
+
+ cid = sys_le16_to_cpu(hdr->cid);
+ net_buf_pull(buf, sizeof(*hdr));
+
+ chan = bt_l2cap_br_lookup_rx_cid(conn, cid);
+ if (!chan) {
+ BT_WARN("Ignoring data for unknown CID 0x%04x", cid);
+ net_buf_unref(buf);
+ return;
+ }
+
+ chan->ops->recv(chan, buf);
+ net_buf_unref(buf);
+}
+
static int l2cap_br_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
{
int i;
diff --git a/net/bluetooth/l2cap_internal.h b/net/bluetooth/l2cap_internal.h
index cc704f298..a56ef6d6b 100644
--- a/net/bluetooth/l2cap_internal.h
+++ b/net/bluetooth/l2cap_internal.h
@@ -280,4 +280,7 @@ int bt_l2cap_br_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf);
* security procedure.
*/
void l2cap_br_encrypt_change(struct bt_conn *conn, uint8_t hci_status);
+
+/* Handle received data */
+void bt_l2cap_br_recv(struct bt_conn *conn, struct net_buf *buf);
#endif /* CONFIG_BLUETOOTH_BREDR */