2016-08-17 23:25:09 +05:30
|
|
|
/** @file
|
|
|
|
* @brief Internal APIs for Bluetooth RFCOMM handling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015-2016 Intel Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 17:19:33 +05:30
|
|
|
#include <bluetooth/rfcomm.h>
|
|
|
|
|
2016-08-17 23:25:09 +05:30
|
|
|
/* RFCOMM signalling connection specific context */
|
|
|
|
struct bt_rfcomm_session {
|
|
|
|
/* L2CAP channel this context is associated with */
|
|
|
|
struct bt_l2cap_br_chan br_chan;
|
2016-08-18 17:19:33 +05:30
|
|
|
struct bt_rfcomm_dlc *dlcs;
|
2016-08-18 16:48:05 +05:30
|
|
|
uint16_t mtu;
|
2016-08-17 23:25:09 +05:30
|
|
|
uint8_t state;
|
2016-08-18 16:48:05 +05:30
|
|
|
bool initiator;
|
2016-08-17 23:25:09 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BT_RFCOMM_STATE_IDLE,
|
|
|
|
BT_RFCOMM_STATE_INIT,
|
2016-08-18 16:48:05 +05:30
|
|
|
BT_RFCOMM_STATE_CONNECTED,
|
2016-08-17 23:25:09 +05:30
|
|
|
};
|
|
|
|
|
2016-08-18 16:17:18 +05:30
|
|
|
struct bt_rfcomm_hdr {
|
|
|
|
uint8_t address;
|
|
|
|
uint8_t control;
|
|
|
|
uint8_t length;
|
|
|
|
} __packed;
|
|
|
|
|
2016-08-18 16:48:05 +05:30
|
|
|
#define BT_RFCOMM_SABM 0x2f
|
|
|
|
#define BT_RFCOMM_UA 0x63
|
|
|
|
#define BT_RFCOMM_UIH 0xef
|
|
|
|
|
|
|
|
struct bt_rfcomm_msg_hdr {
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t len;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
#define BT_RFCOMM_SIG_MIN_MTU 23
|
2016-08-18 16:17:18 +05:30
|
|
|
|
|
|
|
/* Helper to calculate needed outgoing buffer size */
|
|
|
|
#define BT_RFCOMM_BUF_SIZE(mtu) (CONFIG_BLUETOOTH_HCI_SEND_RESERVE + \
|
|
|
|
sizeof(struct bt_hci_acl_hdr) + \
|
|
|
|
sizeof(struct bt_l2cap_hdr) + \
|
|
|
|
sizeof(struct bt_rfcomm_hdr) + (mtu))
|
|
|
|
|
2016-08-18 16:48:05 +05:30
|
|
|
#define BT_RFCOMM_GET_DLCI(addr) (((addr) & 0xfc) >> 2)
|
|
|
|
#define BT_RFCOMM_GET_FRAME_TYPE(ctrl) ((ctrl) & 0xef)
|
|
|
|
|
|
|
|
#define BT_RFCOMM_SET_ADDR(dlci, cr) ((((dlci) & 0x3f) << 2) | \
|
|
|
|
((cr) << 1) | 0x01)
|
|
|
|
#define BT_RFCOMM_SET_CTRL(type, pf) (((type) & 0xef) | ((pf) << 4))
|
|
|
|
#define BT_RFCOMM_SET_LEN_8(len) (((len) << 1) | 1)
|
|
|
|
|
|
|
|
/* Length can be 2 bytes depending on data size */
|
|
|
|
#define BT_RFCOMM_HDR_SIZE (sizeof(struct bt_rfcomm_hdr) + 1)
|
|
|
|
#define BT_RFCOMM_FCS_SIZE 1
|
|
|
|
|
|
|
|
#define BT_RFCOMM_FCS_LEN_UIH 2
|
|
|
|
#define BT_RFCOMM_FCS_LEN_NON_UIH 3
|
|
|
|
|
2016-08-17 23:25:09 +05:30
|
|
|
/* Initialize RFCOMM signal layer */
|
|
|
|
void bt_rfcomm_init(void);
|