diff --git a/include/bluetooth/l2cap.h b/include/bluetooth/l2cap.h index 7922f37ee1a..cfe6834caee 100644 --- a/include/bluetooth/l2cap.h +++ b/include/bluetooth/l2cap.h @@ -79,6 +79,8 @@ struct bt_l2cap_chan_ops { struct bt_buf *buf); }; +#if defined(CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL) + /** @brief L2CAP Server structure. */ struct bt_l2cap_server { /** Server PSM */ @@ -100,5 +102,6 @@ struct bt_l2cap_server { */ int bt_l2cap_server_register(struct bt_l2cap_server *server); +#endif /* CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL */ #endif /* CONFIG_BLUETOOTH_CENTRAL || CONFIG_BLUETOOTH_PERIPHERAL */ #endif /* __BT_L2CAP_H */ diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig index e11fe3e4504..bf7ba7b456c 100644 --- a/net/bluetooth/Kconfig +++ b/net/bluetooth/Kconfig @@ -45,6 +45,11 @@ config BLUETOOTH_SMP prompt "Security Manager Protocol support" default n +config BLUETOOTH_L2CAP_DYNAMIC_CHANNEL + bool + prompt "L2CAP Dynamic Channel support" + default n + config BLUETOOTH_SIGNING bool prompt "Data signing support" diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index ac606701806..213ece9e571 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c @@ -48,7 +48,9 @@ #define L2CAP_LE_CID_END 0x007f static struct bt_l2cap_fixed_chan *channels; +#if defined(CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL) static struct bt_l2cap_server *servers; +#endif /* CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL */ /* L2CAP signalling channel specific context */ struct bt_l2cap { @@ -101,39 +103,6 @@ void bt_l2cap_fixed_chan_register(struct bt_l2cap_fixed_chan *chan) channels = chan; } -static struct bt_l2cap_server *l2cap_server_lookup_psm(uint16_t psm) -{ - struct bt_l2cap_server *server; - - for (server = servers; server; server = server->_next) { - if (server->psm == psm) { - return server; - } - } - - return NULL; -} - -int bt_l2cap_server_register(struct bt_l2cap_server *server) -{ - if (server->psm < 0x0080 || server->psm > 0x00ff || !server->accept) { - return -EINVAL; - } - - /* Check if given PSM is already in use */ - if (l2cap_server_lookup_psm(server->psm)) { - BT_DBG("PSM already registered\n"); - return -EADDRINUSE; - } - - BT_DBG("PSM 0x%04x\n", server->psm); - - server->_next = servers; - servers = server; - - return 0; -} - static void l2cap_chan_alloc_cid(struct bt_conn *conn, struct bt_l2cap_chan *chan) { @@ -332,6 +301,40 @@ static void le_conn_param_update_req(struct bt_l2cap *l2cap, uint8_t ident, } #endif /* CONFIG_BLUETOOTH_CENTRAL */ +#if defined(CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL) +static struct bt_l2cap_server *l2cap_server_lookup_psm(uint16_t psm) +{ + struct bt_l2cap_server *server; + + for (server = servers; server; server = server->_next) { + if (server->psm == psm) { + return server; + } + } + + return NULL; +} + +int bt_l2cap_server_register(struct bt_l2cap_server *server) +{ + if (server->psm < 0x0080 || server->psm > 0x00ff || !server->accept) { + return -EINVAL; + } + + /* Check if given PSM is already in use */ + if (l2cap_server_lookup_psm(server->psm)) { + BT_DBG("PSM already registered\n"); + return -EADDRINUSE; + } + + BT_DBG("PSM 0x%04x\n", server->psm); + + server->_next = servers; + servers = server; + + return 0; +} + static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident, struct bt_buf *buf) { @@ -432,6 +435,7 @@ static void le_conn_req(struct bt_l2cap *l2cap, uint8_t ident, rsp: bt_l2cap_send(conn, BT_L2CAP_CID_LE_SIG, buf); } +#endif /* CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL */ static void l2cap_recv(struct bt_l2cap_chan *chan, struct bt_buf *buf) { @@ -469,9 +473,11 @@ static void l2cap_recv(struct bt_l2cap_chan *chan, struct bt_buf *buf) le_conn_param_update_req(l2cap, hdr->ident, buf); break; #endif /* CONFIG_BLUETOOTH_CENTRAL */ +#if defined(CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL) case BT_L2CAP_LE_CONN_REQ: le_conn_req(l2cap, hdr->ident, buf); break; +#endif /* CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL */ default: BT_WARN("Unknown L2CAP PDU code 0x%02x\n", hdr->code); rej_not_understood(chan->conn, hdr->ident); diff --git a/samples/bluetooth/shell/prj_arm.conf b/samples/bluetooth/shell/prj_arm.conf index 61ec957910e..629abefccb4 100644 --- a/samples/bluetooth/shell/prj_arm.conf +++ b/samples/bluetooth/shell/prj_arm.conf @@ -10,3 +10,4 @@ CONFIG_BLUETOOTH_PERIPHERAL=y CONFIG_BLUETOOTH_SMP=y CONFIG_BLUETOOTH_SIGNING=y CONFIG_BLUETOOTH_GATT_CLIENT=y +CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL=y diff --git a/samples/bluetooth/shell/prj_x86.conf b/samples/bluetooth/shell/prj_x86.conf index 924b3f5adcc..8da2307df65 100644 --- a/samples/bluetooth/shell/prj_x86.conf +++ b/samples/bluetooth/shell/prj_x86.conf @@ -10,5 +10,6 @@ CONFIG_BLUETOOTH_PERIPHERAL=y CONFIG_BLUETOOTH_SMP=y CONFIG_BLUETOOTH_SIGNING=y CONFIG_BLUETOOTH_GATT_CLIENT=y +CONFIG_BLUETOOTH_L2CAP_DYNAMIC_CHANNEL=y CONFIG_TINYCRYPT=y CONFIG_TINYCRYPT_AES=y