mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-13 15:35:22 +00:00
PN (Parameter negotiation) is used to negotiate parameters like mtu. Initial credit for flow control is also sent in PN. If the dlci to which PN requested is not found in the dlc list then it will be treated as incoming dlc request and accept callback will be called to profile. Dlc mtu has to be set by profile (before it returns dlc) which will be negotiated with remote. But the final mtu will be min of mtu provided by profile, mtu sent by remote, and session mtu > ACL Data RX: Handle 256 flags 0x02 dlen 18 [hci0] 210.108444 Channel: 64 len 14 [PSM 3 mode 0] {chan 0} RFCOMM: Unnumbered Info with Header Check (UIH) (0xef) Address: 0x03 cr 1 dlci 0x00 Control: 0xef poll/final 0 Length: 10 FCS: 0x70 MCC Message type: DLC Parameter Negotiation CMD (0x20) Length: 8 dlci 2 frame_type 0 credit_flow 15 pri 7 ack_timer 0 frame_size 122 max_retrans 0 credits 7 < ACL Data TX: Handle 256 flags 0x00 dlen 18 [hci0] 210.111452 Channel: 64 len 14 [PSM 3 mode 0] {chan 0} RFCOMM: Unnumbered Info with Header Check (UIH) (0xef) Address: 0x01 cr 0 dlci 0x00 Control: 0xef poll/final 0 Length: 10 FCS: 0xaa MCC Message type: DLC Parameter Negotiation RSP (0x20) Length: 8 dlci 2 frame_type 0 credit_flow 14 pri 0 ack_timer 0 frame_size 30 max_retrans 0 credits 7 Change-Id: Ifd466db6b3b868d04e38db02ebad6e47ab2da030 Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
136 lines
3.8 KiB
C
136 lines
3.8 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);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
#endif /* __BT_RFCOMM_H */
|