#ifndef _NETBT_RFCOMM_H_
#define _NETBT_RFCOMM_H_
#include <sys/types.h>
#define RFCOMM_MTU_MAX 32767
#define RFCOMM_MTU_MIN 23
#define RFCOMM_MTU_DEFAULT 127
#define RFCOMM_CREDITS_MAX 255
#define RFCOMM_CREDITS_DEFAULT 7
#define RFCOMM_CHANNEL_ANY 0
#define RFCOMM_CHANNEL_MIN 1
#define RFCOMM_CHANNEL_MAX 30
#define RFCOMM_FRAME_SABM 0x2f
#define RFCOMM_FRAME_DISC 0x43
#define RFCOMM_FRAME_UA 0x63
#define RFCOMM_FRAME_DM 0x0f
#define RFCOMM_FRAME_UIH 0xef
#define RFCOMM_MCC_TEST 0x08
#define RFCOMM_MCC_FCON 0x28
#define RFCOMM_MCC_FCOFF 0x18
#define RFCOMM_MCC_MSC 0x38
#define RFCOMM_MCC_RPN 0x24
#define RFCOMM_MCC_RLS 0x14
#define RFCOMM_MCC_PN 0x20
#define RFCOMM_MCC_NSC 0x04
#define RFCOMM_MSC_FC 0x02
#define RFCOMM_MSC_RTC 0x04
#define RFCOMM_MSC_RTR 0x08
#define RFCOMM_MSC_IC 0x40
#define RFCOMM_MSC_DV 0x80
#define RFCOMM_RPN_BR_2400 0x0
#define RFCOMM_RPN_BR_4800 0x1
#define RFCOMM_RPN_BR_7200 0x2
#define RFCOMM_RPN_BR_9600 0x3
#define RFCOMM_RPN_BR_19200 0x4
#define RFCOMM_RPN_BR_38400 0x5
#define RFCOMM_RPN_BR_57600 0x6
#define RFCOMM_RPN_BR_115200 0x7
#define RFCOMM_RPN_BR_230400 0x8
#define RFCOMM_RPN_DATA_5 0x0
#define RFCOMM_RPN_DATA_6 0x1
#define RFCOMM_RPN_DATA_7 0x2
#define RFCOMM_RPN_DATA_8 0x3
#define RFCOMM_RPN_STOP_1 0
#define RFCOMM_RPN_STOP_15 1
#define RFCOMM_RPN_PARITY_NONE 0x0
#define RFCOMM_RPN_PARITY_ODD 0x0
#define RFCOMM_RPN_PARITY_EVEN 0x1
#define RFCOMM_RPN_PARITY_MARK 0x2
#define RFCOMM_RPN_PARITY_SPACE 0x3
#define RFCOMM_RPN_8_N_1 0x03
#define RFCOMM_RPN_XON_CHAR 0x11
#define RFCOMM_RPN_XOFF_CHAR 0x13
#define RFCOMM_RPN_FLOW_NONE 0x00
#define RFCOMM_RPN_PM_RATE 0x0001
#define RFCOMM_RPN_PM_DATA 0x0002
#define RFCOMM_RPN_PM_STOP 0x0004
#define RFCOMM_RPN_PM_PARITY 0x0008
#define RFCOMM_RPN_PM_PTYPE 0x0010
#define RFCOMM_RPN_PM_XON 0x0020
#define RFCOMM_RPN_PM_XOFF 0x0040
#define RFCOMM_RPN_PM_FLOW 0x3f00
#define RFCOMM_RPN_PM_ALL 0x3f7f
struct rfcomm_cmd_hdr
{
uint8_t address;
uint8_t control;
uint8_t length;
uint8_t fcs;
} __attribute__ ((__packed__));
struct rfcomm_mcc_msc
{
uint8_t address;
uint8_t modem;
uint8_t brk;
} __attribute__ ((__packed__));
struct rfcomm_mcc_rpn
{
uint8_t dlci;
uint8_t bit_rate;
uint8_t line_settings;
uint8_t flow_control;
uint8_t xon_char;
uint8_t xoff_char;
uint16_t param_mask;
} __attribute__ ((__packed__));
struct rfcomm_mcc_rls
{
uint8_t address;
uint8_t status;
} __attribute__ ((__packed__));
struct rfcomm_mcc_pn
{
uint8_t dlci;
uint8_t flow_control;
uint8_t priority;
uint8_t ack_timer;
uint16_t mtu;
uint8_t max_retrans;
uint8_t credits;
} __attribute__ ((__packed__));
#define RFCOMM_DLCI(b) (((b) & 0xfc) >> 2)
#define RFCOMM_TYPE(b) (((b) & 0xef))
#define RFCOMM_EA(b) (((b) & 0x01))
#define RFCOMM_CR(b) (((b) & 0x02) >> 1)
#define RFCOMM_PF(b) (((b) & 0x10) >> 4)
#define RFCOMM_CHANNEL(dlci) (((dlci) >> 1) & 0x2f)
#define RFCOMM_DIRECTION(dlci) ((dlci) & 0x1)
#define RFCOMM_MKADDRESS(cr, dlci) \
((((dlci) & 0x3f) << 2) | ((cr) << 1) | 0x01)
#define RFCOMM_MKCONTROL(type, pf) ((((type) & 0xef) | ((pf) << 4)))
#define RFCOMM_MKDLCI(dir, channel) ((((channel) & 0x1f) << 1) | (dir))
#define RFCOMM_MCC_TYPE(b) (((b) & 0xfc) >> 2)
#define RFCOMM_MCC_LENGTH(b) (((b) & 0xfe) >> 1)
#define RFCOMM_MKMCC_TYPE(cr, type) ((((type) << 2) | ((cr) << 1) | 0x01))
#define RFCOMM_RPN_DATA_BITS(line) ((line) & 0x3)
#define RFCOMM_RPN_STOP_BITS(line) (((line) >> 2) & 0x1)
#define RFCOMM_RPN_PARITY(line) (((line) >> 3) & 0x1)
#define SO_RFCOMM_MTU 1
#define SO_RFCOMM_FC_INFO 2
#define SO_RFCOMM_LM 3
struct rfcomm_fc_info {
uint8_t lmodem;
uint8_t rmodem;
uint8_t tx_cred;
uint8_t rx_cred;
uint8_t cfc;
uint8_t reserved;
};
#define RFCOMM_LM_AUTH (1<<0)
#define RFCOMM_LM_ENCRYPT (1<<1)
#define RFCOMM_LM_SECURE (1<<2)
#ifdef _KERNEL
extern int rfcomm_sendspace;
extern int rfcomm_recvspace;
extern int rfcomm_mtu_default;
extern int rfcomm_ack_timeout;
extern int rfcomm_mcc_timeout;
struct rfcomm_credit {
struct rfcomm_dlc *rc_dlc;
uint16_t rc_len;
STAILQ_ENTRY(rfcomm_credit) rc_next;
};
struct rfcomm_session {
struct l2cap_channel *rs_l2cap;
uint16_t rs_flags;
uint16_t rs_state;
uint16_t rs_mtu;
STAILQ_HEAD(,rfcomm_credit) rs_credits;
LIST_HEAD(,rfcomm_dlc) rs_dlcs;
struct callout rs_timeout;
LIST_ENTRY(rfcomm_session) rs_next;
};
LIST_HEAD(rfcomm_session_list, rfcomm_session);
extern struct rfcomm_session_list rfcomm_session_active;
extern struct rfcomm_session_list rfcomm_session_listen;
#define RFCOMM_SESSION_CLOSED 0
#define RFCOMM_SESSION_WAIT_CONNECT 1
#define RFCOMM_SESSION_OPEN 2
#define RFCOMM_SESSION_WAIT_DISCONNECT 3
#define RFCOMM_SESSION_LISTEN 4
#define RFCOMM_SESSION_INITIATOR (1 << 0)
#define RFCOMM_SESSION_CFC (1 << 1)
#define RFCOMM_SESSION_LFC (1 << 2)
#define RFCOMM_SESSION_RFC (1 << 3)
#define RFCOMM_SESSION_FREE (1 << 4)
#define IS_INITIATOR(rs) ((rs)->rs_flags & RFCOMM_SESSION_INITIATOR)
struct rfcomm_dlc {
struct rfcomm_session *rd_session;
uint8_t rd_dlci;
uint16_t rd_flags;
uint16_t rd_state;
uint16_t rd_mtu;
int rd_mode;
struct sockaddr_bt rd_laddr;
struct sockaddr_bt rd_raddr;
uint8_t rd_lmodem;
uint8_t rd_rmodem;
int rd_rxcred;
size_t rd_rxsize;
int rd_txcred;
int rd_pending;
struct callout rd_timeout;
struct mbuf *rd_txbuf;
const struct btproto *rd_proto;
void *rd_upper;
LIST_ENTRY(rfcomm_dlc) rd_next;
};
#define RFCOMM_DLC_DETACH (1 << 0)
#define RFCOMM_DLC_SHUTDOWN (1 << 1)
#define RFCOMM_DLC_CLOSED 0
#define RFCOMM_DLC_WAIT_SESSION 1
#define RFCOMM_DLC_WAIT_CONNECT 2
#define RFCOMM_DLC_WAIT_SEND_SABM 3
#define RFCOMM_DLC_WAIT_SEND_UA 4
#define RFCOMM_DLC_WAIT_RECV_UA 5
#define RFCOMM_DLC_OPEN 6
#define RFCOMM_DLC_WAIT_DISCONNECT 7
#define RFCOMM_DLC_LISTEN 8
extern struct pr_usrreqs rfcomm_usrreqs;
struct socket;
union netmsg;
struct rfcomm_dlc *rfcomm_dlc_lookup(struct rfcomm_session *, int);
struct rfcomm_dlc *rfcomm_dlc_newconn(struct rfcomm_session *, int);
void rfcomm_dlc_close(struct rfcomm_dlc *, int);
void rfcomm_dlc_timeout(void *);
int rfcomm_dlc_setmode(struct rfcomm_dlc *);
int rfcomm_dlc_connect(struct rfcomm_dlc *);
int rfcomm_dlc_open(struct rfcomm_dlc *);
void rfcomm_dlc_start(struct rfcomm_dlc *);
void rfcomm_init(void);
struct rfcomm_session *rfcomm_session_alloc(struct rfcomm_session_list *, struct sockaddr_bt *);
struct rfcomm_session *rfcomm_session_lookup(struct sockaddr_bt *, struct sockaddr_bt *);
void rfcomm_session_free(struct rfcomm_session *);
int rfcomm_session_send_frame(struct rfcomm_session *, int, int);
int rfcomm_session_send_uih(struct rfcomm_session *, struct rfcomm_dlc *, int, struct mbuf *);
int rfcomm_session_send_mcc(struct rfcomm_session *, int, uint8_t, void *, int);
void rfcomm_session_timeout(void *);
int rfcomm_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *);
void rfcomm_ctloutput(union netmsg *);
int rfcomm_attach(struct rfcomm_dlc **, const struct btproto *, void *);
int rfcomm_bind(struct rfcomm_dlc *, struct sockaddr_bt *);
int rfcomm_sockaddr(struct rfcomm_dlc *, struct sockaddr_bt *);
int rfcomm_connect(struct rfcomm_dlc *, struct sockaddr_bt *);
int rfcomm_peeraddr(struct rfcomm_dlc *, struct sockaddr_bt *);
int rfcomm_disconnect(struct rfcomm_dlc *, int);
int rfcomm_detach(struct rfcomm_dlc **);
int rfcomm_listen(struct rfcomm_dlc *);
int rfcomm_send(struct rfcomm_dlc *, struct mbuf *);
int rfcomm_rcvd(struct rfcomm_dlc *, size_t);
int rfcomm_setopt(struct rfcomm_dlc *, int, void *);
int rfcomm_setopt2(struct rfcomm_dlc *, int, struct socket *, struct sockopt *);
int rfcomm_getopt(struct rfcomm_dlc *, int, void *);
extern vm_zone_t rfcomm_credit_pool;
#endif
#endif