diff --git a/include/bluetooth/l2cap.h b/include/bluetooth/l2cap.h new file mode 100644 index 00000000000..7922f37ee1a --- /dev/null +++ b/include/bluetooth/l2cap.h @@ -0,0 +1,104 @@ +/** @file + * @brief Bluetooth L2CAP handling + */ + +/* + * Copyright (c) 2015 Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3) Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __BT_L2CAP_H +#define __BT_L2CAP_H + +#if defined(CONFIG_BLUETOOTH_CENTRAL) || defined(CONFIG_BLUETOOTH_PERIPHERAL) +#include + +/** @brief L2CAP Endpoint structure. */ +struct bt_l2cap_endpoint { + /** Endpoint CID */ + uint16_t cid; + /** Endpoint Maximum PDU payload Size */ + uint16_t mps; + /** Endpoint Maximum Transmission Unit */ + uint16_t mtu; + /** Endpoint credits */ + uint16_t credits; +}; + +/** @brief L2CAP Channel structure. */ +struct bt_l2cap_chan { + /** Channel connection reference */ + struct bt_conn *conn; + + /** Channel operations reference */ + struct bt_l2cap_chan_ops *ops; + + /** Channel Transmission Endpoint */ + struct bt_l2cap_endpoint tx; + /** Channel Receiving Endpoint */ + struct bt_l2cap_endpoint rx; + + struct bt_l2cap_chan *_next; +}; + +/** @brief L2CAP Channel operations structure. */ +struct bt_l2cap_chan_ops { + /** Channel connected callback */ + void (*connected)(struct bt_l2cap_chan *chan); + /** Channel disconnected callback */ + void (*disconnected)(struct bt_l2cap_chan *chan); + /** Channel encrypt_change callback */ + void (*encrypt_change)(struct bt_l2cap_chan *chan); + + /** Channel recv callback */ + void (*recv)(struct bt_l2cap_chan *chan, + struct bt_buf *buf); +}; + +/** @brief L2CAP Server structure. */ +struct bt_l2cap_server { + /** Server PSM */ + uint16_t psm; + + /** Server accept callack */ + int (*accept)(struct bt_conn *conn, struct bt_l2cap_chan **chan); + + struct bt_l2cap_server *_next; +}; + +/** @brief Register attribute database. + * + * Register L2CAP server for a PSM. + * + * @param server Server structure. + * + * @return 0 in case of success or negative value in case of error. + */ +int bt_l2cap_server_register(struct bt_l2cap_server *server); + +#endif /* CONFIG_BLUETOOTH_CENTRAL || CONFIG_BLUETOOTH_PERIPHERAL */ +#endif /* __BT_L2CAP_H */ diff --git a/net/bluetooth/att.c b/net/bluetooth/att.c index ba714a3b59c..b1b755d3661 100644 --- a/net/bluetooth/att.c +++ b/net/bluetooth/att.c @@ -35,7 +35,7 @@ #include "hci_core.h" #include "conn_internal.h" -#include "l2cap.h" +#include "l2cap_internal.h" #include "smp.h" #include "att.h" #include "gatt_internal.h" diff --git a/net/bluetooth/conn.c b/net/bluetooth/conn.c index 2a8d3ce8a00..9a05d6233df 100644 --- a/net/bluetooth/conn.c +++ b/net/bluetooth/conn.c @@ -33,7 +33,7 @@ #include "hci_core.h" #include "conn_internal.h" -#include "l2cap.h" +#include "l2cap_internal.h" #include "keys.h" #include "smp.h" diff --git a/net/bluetooth/gatt.c b/net/bluetooth/gatt.c index 1bf4265d1d0..58d012a13db 100644 --- a/net/bluetooth/gatt.c +++ b/net/bluetooth/gatt.c @@ -35,7 +35,7 @@ #include "hci_core.h" #include "conn_internal.h" #include "keys.h" -#include "l2cap.h" +#include "l2cap_internal.h" #include "att.h" #include "smp.h" #include "gatt_internal.h" diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 1c152f3862f..278706ead5d 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -35,7 +35,7 @@ #include "hci_core.h" #include "keys.h" #include "conn_internal.h" -#include "l2cap.h" +#include "l2cap_internal.h" #include "stack.h" #if !defined(CONFIG_BLUETOOTH_DEBUG_HCI_CORE) diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index 98b2c86db29..5928c340c12 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c @@ -32,7 +32,7 @@ #include "hci_core.h" #include "conn_internal.h" -#include "l2cap.h" +#include "l2cap_internal.h" #include "att.h" #include "smp.h" diff --git a/net/bluetooth/l2cap.h b/net/bluetooth/l2cap_internal.h similarity index 98% rename from net/bluetooth/l2cap.h rename to net/bluetooth/l2cap_internal.h index 34185db78f5..d73a5f32a98 100644 --- a/net/bluetooth/l2cap.h +++ b/net/bluetooth/l2cap_internal.h @@ -1,4 +1,6 @@ -/* l2cap.h - L2CAP handling */ +/** @file + * @brief Internal APIs for Bluetooth L2CAP handling. + */ /* * Copyright (c) 2015 Intel Corporation diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index f98a04cf80c..d13b0879179 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -40,7 +40,7 @@ #include "hci_core.h" #include "keys.h" #include "conn_internal.h" -#include "l2cap.h" +#include "l2cap_internal.h" #include "smp.h" #include "stack.h" diff --git a/net/bluetooth/smp_null.c b/net/bluetooth/smp_null.c index 56093b79d42..524f8990c70 100644 --- a/net/bluetooth/smp_null.c +++ b/net/bluetooth/smp_null.c @@ -21,7 +21,7 @@ #include #include -#include "l2cap.h" +#include "l2cap_internal.h" #include "smp.h" int bt_smp_sign_verify(struct bt_conn *conn, struct bt_buf *buf)