zephyr/include/bluetooth/rfcomm.h
Jaganath Kanakkassery 623ce45fc9 Bluetooth: RFCOMM: Remove BT_RFCOMM_SEND_RESERVE
Profiles should use bt_rfcomm_create_pdu() hereafter.

Change-Id: I2fcbbd910005ec5b7b8d75ca452a63c21e6964ea
Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
2016-09-07 08:17:26 +03:00

157 lines
4.4 KiB
C

/** @file
* @brief Bluetooth RFCOMM handling
*/
/*
* Copyright (c) 2015-2016 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_RFCOMM_H
#define __BT_RFCOMM_H
/**
* @brief RFCOMM
* @defgroup bt_rfcomm RFCOMM
* @ingroup bluetooth
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <bluetooth/buf.h>
#include <bluetooth/conn.h>
struct bt_rfcomm_dlc;
/** @brief RFCOMM DLC operations structure. */
struct bt_rfcomm_dlc_ops {
/** DLC connected callback
*
* If this callback is provided it will be called whenever the
* connection completes.
*
* @param dlc The dlc that has been connected
*/
void (*connected)(struct bt_rfcomm_dlc *dlc);
/** DLC disconnected callback
*
* If this callback is provided it will be called whenever the
* dlc is disconnected, including when a connection gets
* rejected.
*
* @param dlc The dlc that has been Disconnected
*/
void (*disconnected)(struct bt_rfcomm_dlc *dlc);
/** DLC recv callback
*
* @param dlc The dlc receiving data.
* @param buf Buffer containing incoming data.
*/
void (*recv)(struct bt_rfcomm_dlc *dlc, struct net_buf *buf);
};
/** @brief RFCOMM DLC structure. */
struct bt_rfcomm_dlc {
struct bt_rfcomm_session *session;
struct bt_rfcomm_dlc_ops *ops;
struct bt_rfcomm_dlc *_next;
uint16_t mtu;
uint8_t dlci;
uint8_t state;
uint8_t tx_credit;
uint8_t rx_credit;
bool initiator;
};
struct bt_rfcomm_server {
/** Server Channel */
uint8_t channel;
/** Server accept callback
*
* This callback is called whenever a new incoming connection requires
* authorization.
*
* @param conn The connection that is requesting authorization
* @param dlc Pointer to received the allocated dlc
*
* @return 0 in case of success or negative value in case of error.
*/
int (*accept)(struct bt_conn *conn, struct bt_rfcomm_dlc **dlc);
struct bt_rfcomm_server *_next;
};
/** @brief Register RFCOMM server
*
* Register RFCOMM server for a channel, each new connection is authorized
* using the accept() callback which in case of success shall allocate the dlc
* structure to be used by the new connection.
*
* @param server Server structure.
*
* @return 0 in case of success or negative value in case of error.
*/
int bt_rfcomm_server_register(struct bt_rfcomm_server *server);
/** @brief Send data to RFCOMM
*
* Send data from buffer to the dlc. Length should be less than or equal to
* mtu.
*
* @param dlc Dlc object.
* @param buf Data buffer.
*
* @return Bytes sent in case of success or negative value in case of error.
*/
int bt_rfcomm_dlc_send(struct bt_rfcomm_dlc *dlc, struct net_buf *buf);
/** @brief Get the buffer from fifo after reserving head room for RFCOMM, L2CAP
* and ACL headers.
*
* @param fifo Which FIFO to take the buffer from.
*
* @return New buffer.
*/
struct net_buf *bt_rfcomm_create_pdu(struct nano_fifo *fifo);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* __BT_RFCOMM_H */