Home | History | Annotate | Line # | Download | only in netbt
rfcomm.h revision 1.4
      1  1.4   plunky /*	$NetBSD: rfcomm.h,v 1.4 2007/11/03 17:20:17 plunky Exp $	*/
      2  1.1  gdamore 
      3  1.1  gdamore /*-
      4  1.1  gdamore  * Copyright (c) 2006 Itronix Inc.
      5  1.1  gdamore  * All rights reserved.
      6  1.1  gdamore  *
      7  1.1  gdamore  * Written by Iain Hibbert for Itronix Inc.
      8  1.1  gdamore  *
      9  1.1  gdamore  * Redistribution and use in source and binary forms, with or without
     10  1.1  gdamore  * modification, are permitted provided that the following conditions
     11  1.1  gdamore  * are met:
     12  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     13  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     14  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  gdamore  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  gdamore  *    documentation and/or other materials provided with the distribution.
     17  1.1  gdamore  * 3. The name of Itronix Inc. may not be used to endorse
     18  1.1  gdamore  *    or promote products derived from this software without specific
     19  1.1  gdamore  *    prior written permission.
     20  1.1  gdamore  *
     21  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
     22  1.1  gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  1.1  gdamore  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  1.1  gdamore  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     25  1.1  gdamore  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     26  1.1  gdamore  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     27  1.1  gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     28  1.1  gdamore  * ON ANY THEORY OF LIABILITY, WHETHER IN
     29  1.1  gdamore  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  1.1  gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  1.1  gdamore  * POSSIBILITY OF SUCH DAMAGE.
     32  1.1  gdamore  */
     33  1.1  gdamore /*-
     34  1.1  gdamore  * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin (at) yahoo.com>
     35  1.1  gdamore  * All rights reserved.
     36  1.1  gdamore  *
     37  1.1  gdamore  * Redistribution and use in source and binary forms, with or without
     38  1.1  gdamore  * modification, are permitted provided that the following conditions
     39  1.1  gdamore  * are met:
     40  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     41  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     42  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     43  1.1  gdamore  *    notice, this list of conditions and the following disclaimer in the
     44  1.1  gdamore  *    documentation and/or other materials provided with the distribution.
     45  1.1  gdamore  *
     46  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     47  1.1  gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     48  1.1  gdamore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     49  1.1  gdamore  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     50  1.1  gdamore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     51  1.1  gdamore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     52  1.1  gdamore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     53  1.1  gdamore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     54  1.1  gdamore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     55  1.1  gdamore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     56  1.1  gdamore  * SUCH DAMAGE.
     57  1.1  gdamore  *
     58  1.4   plunky  * $Id: rfcomm.h,v 1.4 2007/11/03 17:20:17 plunky Exp $
     59  1.1  gdamore  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h,v 1.4 2005/01/11 01:39:53 emax Exp $
     60  1.1  gdamore  */
     61  1.1  gdamore 
     62  1.1  gdamore #ifndef _NETBT_RFCOMM_H_
     63  1.1  gdamore #define _NETBT_RFCOMM_H_
     64  1.1  gdamore 
     65  1.2   plunky #include <sys/types.h>
     66  1.2   plunky 
     67  1.1  gdamore /*************************************************************************
     68  1.1  gdamore  *************************************************************************
     69  1.1  gdamore  **				RFCOMM					**
     70  1.1  gdamore  *************************************************************************
     71  1.1  gdamore  *************************************************************************/
     72  1.1  gdamore 
     73  1.1  gdamore #define RFCOMM_MTU_MAX			32767
     74  1.1  gdamore #define RFCOMM_MTU_MIN			23
     75  1.1  gdamore #define RFCOMM_MTU_DEFAULT		127
     76  1.1  gdamore 
     77  1.1  gdamore #define RFCOMM_CREDITS_MAX		255	/* in any single packet */
     78  1.1  gdamore #define RFCOMM_CREDITS_DEFAULT		7	/* default initial value */
     79  1.1  gdamore 
     80  1.1  gdamore #define RFCOMM_CHANNEL_MIN		1
     81  1.1  gdamore #define RFCOMM_CHANNEL_MAX		30
     82  1.1  gdamore 
     83  1.1  gdamore /* RFCOMM frame types */
     84  1.1  gdamore #define RFCOMM_FRAME_SABM		0x2f
     85  1.1  gdamore #define RFCOMM_FRAME_DISC		0x43
     86  1.1  gdamore #define RFCOMM_FRAME_UA			0x63
     87  1.1  gdamore #define RFCOMM_FRAME_DM			0x0f
     88  1.1  gdamore #define RFCOMM_FRAME_UIH		0xef
     89  1.1  gdamore 
     90  1.1  gdamore /* RFCOMM MCC commands */
     91  1.1  gdamore #define RFCOMM_MCC_TEST			0x08	/* Test */
     92  1.1  gdamore #define RFCOMM_MCC_FCON			0x28	/* Flow Control on */
     93  1.1  gdamore #define RFCOMM_MCC_FCOFF		0x18	/* Flow Control off */
     94  1.1  gdamore #define RFCOMM_MCC_MSC			0x38	/* Modem Status Command */
     95  1.1  gdamore #define RFCOMM_MCC_RPN			0x24	/* Remote Port Negotiation */
     96  1.1  gdamore #define RFCOMM_MCC_RLS			0x14	/* Remote Line Status */
     97  1.1  gdamore #define RFCOMM_MCC_PN			0x20	/* Port Negotiation */
     98  1.1  gdamore #define RFCOMM_MCC_NSC			0x04	/* Non Supported Command */
     99  1.1  gdamore 
    100  1.1  gdamore /* RFCOMM modem signals */
    101  1.1  gdamore #define RFCOMM_MSC_FC			0x02	/* Flow Control asserted */
    102  1.1  gdamore #define RFCOMM_MSC_RTC			0x04	/* Ready To Communicate */
    103  1.1  gdamore #define RFCOMM_MSC_RTR			0x08	/* Ready To Receive */
    104  1.1  gdamore #define RFCOMM_MSC_IC			0x40	/* Incomming Call (RING) */
    105  1.1  gdamore #define RFCOMM_MSC_DV			0x80	/* Data Valid */
    106  1.1  gdamore 
    107  1.1  gdamore /* RPN parameters - baud rate */
    108  1.1  gdamore #define RFCOMM_RPN_BR_2400		0x0
    109  1.1  gdamore #define RFCOMM_RPN_BR_4800		0x1
    110  1.1  gdamore #define RFCOMM_RPN_BR_7200		0x2
    111  1.1  gdamore #define RFCOMM_RPN_BR_9600		0x3
    112  1.1  gdamore #define RFCOMM_RPN_BR_19200		0x4
    113  1.1  gdamore #define RFCOMM_RPN_BR_38400		0x5
    114  1.1  gdamore #define RFCOMM_RPN_BR_57600		0x6
    115  1.1  gdamore #define RFCOMM_RPN_BR_115200		0x7
    116  1.1  gdamore #define RFCOMM_RPN_BR_230400		0x8
    117  1.1  gdamore 
    118  1.1  gdamore /* RPN parameters - data bits */
    119  1.1  gdamore #define RFCOMM_RPN_DATA_5		0x0
    120  1.1  gdamore #define RFCOMM_RPN_DATA_6		0x1
    121  1.1  gdamore #define RFCOMM_RPN_DATA_7		0x2
    122  1.1  gdamore #define RFCOMM_RPN_DATA_8		0x3
    123  1.1  gdamore 
    124  1.1  gdamore /* RPN parameters - stop bit */
    125  1.1  gdamore #define RFCOMM_RPN_STOP_1		0
    126  1.1  gdamore #define RFCOMM_RPN_STOP_15		1
    127  1.1  gdamore 
    128  1.1  gdamore /* RPN parameters - parity enable */
    129  1.1  gdamore #define RFCOMM_RPN_PARITY_NONE		0x0
    130  1.1  gdamore 
    131  1.1  gdamore /* RPN parameters - parity type */
    132  1.1  gdamore #define RFCOMM_RPN_PARITY_ODD		0x0
    133  1.1  gdamore #define RFCOMM_RPN_PARITY_EVEN		0x1
    134  1.1  gdamore #define RFCOMM_RPN_PARITY_MARK		0x2
    135  1.1  gdamore #define RFCOMM_RPN_PARITY_SPACE		0x3
    136  1.1  gdamore 
    137  1.1  gdamore /* RPN parameters - default line_setting */
    138  1.1  gdamore #define RFCOMM_RPN_8_N_1		0x03
    139  1.1  gdamore 
    140  1.1  gdamore /* RPN parameters - flow control */
    141  1.1  gdamore #define RFCOMM_RPN_XON_CHAR		0x11
    142  1.1  gdamore #define RFCOMM_RPN_XOFF_CHAR		0x13
    143  1.1  gdamore #define RFCOMM_RPN_FLOW_NONE		0x00
    144  1.1  gdamore 
    145  1.1  gdamore /* RPN parameters - mask */
    146  1.1  gdamore #define RFCOMM_RPN_PM_RATE		0x0001
    147  1.1  gdamore #define RFCOMM_RPN_PM_DATA		0x0002
    148  1.1  gdamore #define RFCOMM_RPN_PM_STOP		0x0004
    149  1.1  gdamore #define RFCOMM_RPN_PM_PARITY		0x0008
    150  1.1  gdamore #define RFCOMM_RPN_PM_PTYPE		0x0010
    151  1.1  gdamore #define RFCOMM_RPN_PM_XON		0x0020
    152  1.1  gdamore #define RFCOMM_RPN_PM_XOFF		0x0040
    153  1.1  gdamore 
    154  1.1  gdamore #define RFCOMM_RPN_PM_FLOW		0x3f00
    155  1.1  gdamore 
    156  1.1  gdamore #define RFCOMM_RPN_PM_ALL		0x3f7f
    157  1.1  gdamore 
    158  1.1  gdamore /* RFCOMM command frame header */
    159  1.1  gdamore struct rfcomm_cmd_hdr
    160  1.1  gdamore {
    161  1.1  gdamore 	uint8_t		address;
    162  1.1  gdamore 	uint8_t		control;
    163  1.1  gdamore 	uint8_t		length;
    164  1.1  gdamore 	uint8_t		fcs;
    165  1.1  gdamore } __attribute__ ((__packed__));
    166  1.1  gdamore 
    167  1.1  gdamore /* RFCOMM MSC command */
    168  1.1  gdamore struct rfcomm_mcc_msc
    169  1.1  gdamore {
    170  1.1  gdamore 	uint8_t		address;
    171  1.1  gdamore 	uint8_t		modem;
    172  1.1  gdamore 	uint8_t		brk;
    173  1.1  gdamore } __attribute__ ((__packed__));
    174  1.1  gdamore 
    175  1.1  gdamore /* RFCOMM RPN command */
    176  1.1  gdamore struct rfcomm_mcc_rpn
    177  1.1  gdamore {
    178  1.1  gdamore 	uint8_t		dlci;
    179  1.1  gdamore 	uint8_t		bit_rate;
    180  1.1  gdamore 	uint8_t		line_settings;
    181  1.1  gdamore 	uint8_t		flow_control;
    182  1.1  gdamore 	uint8_t		xon_char;
    183  1.1  gdamore 	uint8_t		xoff_char;
    184  1.1  gdamore 	uint16_t	param_mask;
    185  1.1  gdamore } __attribute__ ((__packed__));
    186  1.1  gdamore 
    187  1.1  gdamore /* RFCOMM RLS command */
    188  1.1  gdamore struct rfcomm_mcc_rls
    189  1.1  gdamore {
    190  1.1  gdamore 	uint8_t		address;
    191  1.1  gdamore 	uint8_t		status;
    192  1.1  gdamore } __attribute__ ((__packed__));
    193  1.1  gdamore 
    194  1.1  gdamore /* RFCOMM PN command */
    195  1.1  gdamore struct rfcomm_mcc_pn
    196  1.1  gdamore {
    197  1.1  gdamore 	uint8_t		dlci;
    198  1.1  gdamore 	uint8_t		flow_control;
    199  1.1  gdamore 	uint8_t		priority;
    200  1.1  gdamore 	uint8_t		ack_timer;
    201  1.1  gdamore 	uint16_t	mtu;
    202  1.1  gdamore 	uint8_t		max_retrans;
    203  1.1  gdamore 	uint8_t		credits;
    204  1.1  gdamore } __attribute__ ((__packed__));
    205  1.1  gdamore 
    206  1.1  gdamore /* RFCOMM frame parsing macros */
    207  1.1  gdamore #define RFCOMM_DLCI(b)			(((b) & 0xfc) >> 2)
    208  1.1  gdamore #define RFCOMM_TYPE(b)			(((b) & 0xef))
    209  1.1  gdamore 
    210  1.1  gdamore #define RFCOMM_EA(b)			(((b) & 0x01))
    211  1.1  gdamore #define RFCOMM_CR(b)			(((b) & 0x02) >> 1)
    212  1.1  gdamore #define RFCOMM_PF(b)			(((b) & 0x10) >> 4)
    213  1.1  gdamore 
    214  1.1  gdamore #define RFCOMM_CHANNEL(dlci)		(((dlci) >> 1) & 0x2f)
    215  1.1  gdamore #define RFCOMM_DIRECTION(dlci)		((dlci) & 0x1)
    216  1.1  gdamore 
    217  1.1  gdamore #define RFCOMM_MKADDRESS(cr, dlci) \
    218  1.1  gdamore 	((((dlci) & 0x3f) << 2) | ((cr) << 1) | 0x01)
    219  1.1  gdamore 
    220  1.1  gdamore #define RFCOMM_MKCONTROL(type, pf)	((((type) & 0xef) | ((pf) << 4)))
    221  1.1  gdamore #define RFCOMM_MKDLCI(dir, channel)	((((channel) & 0x1f) << 1) | (dir))
    222  1.1  gdamore 
    223  1.1  gdamore /* RFCOMM MCC macros */
    224  1.1  gdamore #define RFCOMM_MCC_TYPE(b)		(((b) & 0xfc) >> 2)
    225  1.1  gdamore #define RFCOMM_MCC_LENGTH(b)		(((b) & 0xfe) >> 1)
    226  1.1  gdamore #define RFCOMM_MKMCC_TYPE(cr, type)	((((type) << 2) | ((cr) << 1) | 0x01))
    227  1.1  gdamore 
    228  1.1  gdamore /* RPN macros */
    229  1.1  gdamore #define RFCOMM_RPN_DATA_BITS(line)	((line) & 0x3)
    230  1.1  gdamore #define RFCOMM_RPN_STOP_BITS(line)	(((line) >> 2) & 0x1)
    231  1.1  gdamore #define RFCOMM_RPN_PARITY(line)		(((line) >> 3) & 0x1)
    232  1.1  gdamore 
    233  1.1  gdamore /*************************************************************************
    234  1.1  gdamore  *************************************************************************
    235  1.1  gdamore  **			SOCK_STREAM RFCOMM sockets			**
    236  1.1  gdamore  *************************************************************************
    237  1.1  gdamore  *************************************************************************/
    238  1.1  gdamore 
    239  1.3   plunky /* Socket options */
    240  1.1  gdamore #define SO_RFCOMM_MTU		1	/* mtu */
    241  1.1  gdamore #define SO_RFCOMM_FC_INFO	2	/* flow control info (below) */
    242  1.3   plunky #define SO_RFCOMM_LM		3	/* link mode */
    243  1.1  gdamore 
    244  1.1  gdamore /* Flow control information */
    245  1.1  gdamore struct rfcomm_fc_info {
    246  1.1  gdamore 	uint8_t		lmodem;		/* modem signals (local) */
    247  1.1  gdamore 	uint8_t		rmodem;		/* modem signals (remote) */
    248  1.1  gdamore 	uint8_t		tx_cred;	/* TX credits */
    249  1.1  gdamore 	uint8_t		rx_cred;	/* RX credits */
    250  1.1  gdamore 	uint8_t		cfc;		/* credit flow control */
    251  1.1  gdamore 	uint8_t		reserved;
    252  1.1  gdamore };
    253  1.1  gdamore 
    254  1.3   plunky /* RFCOMM link mode flags */
    255  1.3   plunky #define RFCOMM_LM_AUTH		(1<<0)	/* want authentication */
    256  1.3   plunky #define RFCOMM_LM_ENCRYPT	(1<<1)	/* want encryption */
    257  1.3   plunky #define RFCOMM_LM_SECURE	(1<<2)	/* want secured link */
    258  1.3   plunky 
    259  1.1  gdamore #ifdef _KERNEL
    260  1.1  gdamore 
    261  1.1  gdamore /* sysctl variables */
    262  1.1  gdamore extern int rfcomm_sendspace;
    263  1.1  gdamore extern int rfcomm_recvspace;
    264  1.1  gdamore extern int rfcomm_mtu_default;
    265  1.1  gdamore extern int rfcomm_ack_timeout;
    266  1.1  gdamore extern int rfcomm_mcc_timeout;
    267  1.1  gdamore 
    268  1.1  gdamore /*
    269  1.1  gdamore  * Bluetooth RFCOMM session data
    270  1.1  gdamore  * One L2CAP connection == one RFCOMM session
    271  1.1  gdamore  */
    272  1.1  gdamore 
    273  1.1  gdamore /* Credit note */
    274  1.1  gdamore struct rfcomm_credit {
    275  1.1  gdamore 	struct rfcomm_dlc		*rc_dlc;	/* owner */
    276  1.1  gdamore 	uint16_t			 rc_len;	/* length */
    277  1.1  gdamore 	SIMPLEQ_ENTRY(rfcomm_credit)	 rc_next;	/* next credit */
    278  1.1  gdamore };
    279  1.1  gdamore 
    280  1.1  gdamore /* RFCOMM session data (one L2CAP channel) */
    281  1.1  gdamore struct rfcomm_session {
    282  1.1  gdamore 	struct l2cap_channel		*rs_l2cap;	/* L2CAP pointer */
    283  1.1  gdamore 	uint16_t			 rs_flags;	/* session flags */
    284  1.1  gdamore 	uint16_t			 rs_state;	/* session state */
    285  1.1  gdamore 	uint16_t			 rs_mtu;	/* default MTU */
    286  1.1  gdamore 
    287  1.1  gdamore 	SIMPLEQ_HEAD(,rfcomm_credit)	 rs_credits;	/* credit notes */
    288  1.1  gdamore 	LIST_HEAD(,rfcomm_dlc)		 rs_dlcs;	/* DLC list */
    289  1.1  gdamore 
    290  1.4   plunky 	callout_t			 rs_timeout;	/* timeout */
    291  1.1  gdamore 
    292  1.1  gdamore 	LIST_ENTRY(rfcomm_session)	 rs_next;	/* next session */
    293  1.1  gdamore };
    294  1.1  gdamore 
    295  1.1  gdamore LIST_HEAD(rfcomm_session_list, rfcomm_session);
    296  1.1  gdamore extern struct rfcomm_session_list rfcomm_session_active;
    297  1.1  gdamore extern struct rfcomm_session_list rfcomm_session_listen;
    298  1.1  gdamore 
    299  1.1  gdamore /* Session state */
    300  1.1  gdamore #define RFCOMM_SESSION_CLOSED		0
    301  1.1  gdamore #define RFCOMM_SESSION_WAIT_CONNECT	1
    302  1.1  gdamore #define RFCOMM_SESSION_OPEN		2
    303  1.1  gdamore #define RFCOMM_SESSION_WAIT_DISCONNECT	3
    304  1.1  gdamore #define RFCOMM_SESSION_LISTEN		4
    305  1.1  gdamore 
    306  1.1  gdamore /* Session flags */
    307  1.1  gdamore #define RFCOMM_SESSION_INITIATOR	(1 << 0) /* we are initiator */
    308  1.1  gdamore #define RFCOMM_SESSION_CFC		(1 << 1) /* credit flow control */
    309  1.1  gdamore #define RFCOMM_SESSION_LFC		(1 << 2) /* local flow control */
    310  1.1  gdamore #define RFCOMM_SESSION_RFC		(1 << 3) /* remote flow control */
    311  1.1  gdamore #define RFCOMM_SESSION_FREE		(1 << 4) /* self lock out for free */
    312  1.1  gdamore 
    313  1.1  gdamore #define IS_INITIATOR(rs)	((rs)->rs_flags & RFCOMM_SESSION_INITIATOR)
    314  1.1  gdamore 
    315  1.1  gdamore /* Bluetooth RFCOMM DLC data (connection) */
    316  1.1  gdamore struct rfcomm_dlc {
    317  1.1  gdamore 	struct rfcomm_session	*rd_session; /* RFCOMM session */
    318  1.1  gdamore 	uint8_t			 rd_dlci;    /* RFCOMM DLCI */
    319  1.1  gdamore 
    320  1.1  gdamore 	uint16_t		 rd_flags;   /* DLC flags */
    321  1.1  gdamore 	uint16_t		 rd_state;   /* DLC state */
    322  1.1  gdamore 	uint16_t		 rd_mtu;     /* MTU */
    323  1.3   plunky 	int			 rd_mode;    /* link mode */
    324  1.1  gdamore 
    325  1.1  gdamore 	struct sockaddr_bt	 rd_laddr;   /* local address */
    326  1.1  gdamore 	struct sockaddr_bt	 rd_raddr;   /* remote address */
    327  1.1  gdamore 
    328  1.1  gdamore 	uint8_t			 rd_lmodem;  /* local modem signls */
    329  1.1  gdamore 	uint8_t			 rd_rmodem;  /* remote modem signals */
    330  1.1  gdamore 
    331  1.1  gdamore 	int			 rd_rxcred;  /* receive credits (sent) */
    332  1.1  gdamore 	size_t			 rd_rxsize;  /* receive buffer (bytes, avail) */
    333  1.1  gdamore 	int			 rd_txcred;  /* transmit credits (unused) */
    334  1.1  gdamore 	int			 rd_pending; /* packets sent but not complete */
    335  1.1  gdamore 
    336  1.1  gdamore 	struct callout		 rd_timeout; /* timeout */
    337  1.1  gdamore 	struct mbuf		*rd_txbuf;   /* transmit buffer */
    338  1.1  gdamore 
    339  1.1  gdamore 	const struct btproto	*rd_proto;   /* upper layer callbacks */
    340  1.1  gdamore 	void			*rd_upper;   /* upper layer argument */
    341  1.1  gdamore 
    342  1.1  gdamore 	LIST_ENTRY(rfcomm_dlc)	 rd_next;    /* next dlc on session */
    343  1.1  gdamore };
    344  1.1  gdamore 
    345  1.1  gdamore /*
    346  1.1  gdamore  * Credit Flow Control works in the following way.
    347  1.1  gdamore  *
    348  1.1  gdamore  * txcred is how many packets we can send. Received credit
    349  1.1  gdamore  * is added to this value, and it is decremented each time
    350  1.1  gdamore  * we send a packet.
    351  1.1  gdamore  *
    352  1.1  gdamore  * rxsize is the number of bytes that are available in the
    353  1.1  gdamore  * upstream receive buffer.
    354  1.1  gdamore  *
    355  1.1  gdamore  * rxcred is the number of credits that we have previously
    356  1.1  gdamore  * sent that are still unused. This value will be decreased
    357  1.1  gdamore  * for each packet we receive and we will add to it when we
    358  1.1  gdamore  * send credits. We calculate the amount of credits to send
    359  1.1  gdamore  * by the cunning formula "(space / mtu) - sent" so that if
    360  1.1  gdamore  * we get a bunch of small packets, we can continue sending
    361  1.1  gdamore  * credits without risking buffer overflow.
    362  1.1  gdamore  */
    363  1.1  gdamore 
    364  1.1  gdamore /* DLC flags */
    365  1.1  gdamore #define RFCOMM_DLC_DETACH		(1 << 0) /* DLC to be detached */
    366  1.1  gdamore #define RFCOMM_DLC_SHUTDOWN		(1 << 1) /* DLC to be shutdown */
    367  1.1  gdamore 
    368  1.1  gdamore /* DLC state */
    369  1.1  gdamore #define RFCOMM_DLC_CLOSED		0	/* no session */
    370  1.1  gdamore #define RFCOMM_DLC_WAIT_SESSION		1	/* waiting for session */
    371  1.1  gdamore #define RFCOMM_DLC_WAIT_CONNECT		2	/* waiting for connect */
    372  1.3   plunky #define RFCOMM_DLC_WAIT_SEND_SABM	3	/* waiting to send SABM */
    373  1.3   plunky #define RFCOMM_DLC_WAIT_SEND_UA		4	/* waiting to send UA */
    374  1.3   plunky #define RFCOMM_DLC_WAIT_RECV_UA		5	/* waiting to receive UA */
    375  1.3   plunky #define RFCOMM_DLC_OPEN			6	/* can send/receive */
    376  1.3   plunky #define RFCOMM_DLC_WAIT_DISCONNECT	7	/* waiting for disconnect */
    377  1.3   plunky #define RFCOMM_DLC_LISTEN		8	/* listening DLC */
    378  1.1  gdamore 
    379  1.1  gdamore /*
    380  1.1  gdamore  * Bluetooth RFCOMM socket kernel prototypes
    381  1.1  gdamore  */
    382  1.1  gdamore 
    383  1.1  gdamore struct socket;
    384  1.1  gdamore 
    385  1.1  gdamore /* rfcomm_dlc.c */
    386  1.1  gdamore struct rfcomm_dlc *rfcomm_dlc_lookup(struct rfcomm_session *, int);
    387  1.1  gdamore struct rfcomm_dlc *rfcomm_dlc_newconn(struct rfcomm_session *, int);
    388  1.1  gdamore void rfcomm_dlc_close(struct rfcomm_dlc *, int);
    389  1.1  gdamore void rfcomm_dlc_timeout(void *);
    390  1.3   plunky int rfcomm_dlc_setmode(struct rfcomm_dlc *);
    391  1.1  gdamore int rfcomm_dlc_connect(struct rfcomm_dlc *);
    392  1.3   plunky int rfcomm_dlc_open(struct rfcomm_dlc *);
    393  1.1  gdamore void rfcomm_dlc_start(struct rfcomm_dlc *);
    394  1.1  gdamore 
    395  1.1  gdamore /* rfcomm_session.c */
    396  1.1  gdamore struct rfcomm_session *rfcomm_session_alloc(struct rfcomm_session_list *, struct sockaddr_bt *);
    397  1.1  gdamore struct rfcomm_session *rfcomm_session_lookup(struct sockaddr_bt *, struct sockaddr_bt *);
    398  1.1  gdamore void rfcomm_session_free(struct rfcomm_session *);
    399  1.1  gdamore int rfcomm_session_send_frame(struct rfcomm_session *, int, int);
    400  1.1  gdamore int rfcomm_session_send_uih(struct rfcomm_session *, struct rfcomm_dlc *, int, struct mbuf *);
    401  1.1  gdamore int rfcomm_session_send_mcc(struct rfcomm_session *, int, uint8_t, void *, int);
    402  1.1  gdamore 
    403  1.1  gdamore /* rfcomm_socket.c */
    404  1.1  gdamore int rfcomm_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
    405  1.1  gdamore int rfcomm_ctloutput(int, struct socket *, int, int, struct mbuf **);
    406  1.1  gdamore 
    407  1.1  gdamore /* rfcomm_upper.c */
    408  1.1  gdamore int rfcomm_attach(struct rfcomm_dlc **, const struct btproto *, void *);
    409  1.1  gdamore int rfcomm_bind(struct rfcomm_dlc *, struct sockaddr_bt *);
    410  1.1  gdamore int rfcomm_sockaddr(struct rfcomm_dlc *, struct sockaddr_bt *);
    411  1.1  gdamore int rfcomm_connect(struct rfcomm_dlc *, struct sockaddr_bt *);
    412  1.1  gdamore int rfcomm_peeraddr(struct rfcomm_dlc *, struct sockaddr_bt *);
    413  1.1  gdamore int rfcomm_disconnect(struct rfcomm_dlc *, int);
    414  1.1  gdamore int rfcomm_detach(struct rfcomm_dlc **);
    415  1.1  gdamore int rfcomm_listen(struct rfcomm_dlc *);
    416  1.1  gdamore int rfcomm_send(struct rfcomm_dlc *, struct mbuf *);
    417  1.1  gdamore int rfcomm_rcvd(struct rfcomm_dlc *, size_t);
    418  1.1  gdamore int rfcomm_setopt(struct rfcomm_dlc *, int, void *);
    419  1.1  gdamore int rfcomm_getopt(struct rfcomm_dlc *, int, void *);
    420  1.1  gdamore 
    421  1.1  gdamore #endif /* _KERNEL */
    422  1.1  gdamore 
    423  1.1  gdamore #endif /* _NETBT_RFCOMM_H_ */
    424